Hi I want to have a clipping plane on my camera that is similar to the near-clipping plane but instead of being perpendicular to the camera, I want it to be a plane in world space.
Here is a diagram to help explain, on the left is how the standard near clip plane works (yellow being what is rendered) but I want it to behave like on the right, with the yellow line being a plane in 3d space.
Calculate world camera position and world vertex position distance by using only x and z using pitagora. Discard every pixel that wants to render before that
Thanks
The issue with this though is that this shader would have to be applied to every single gameobject in the scene in order to work, I’m looking more for something just on the camera
Even if Unity exposed user clip planes, a feature of DirectX and OpenGL to allow for arbitrary clipping planes, you’d still need to use a custom shader to take advantage of them.
The camera doesn’t have a shader, in fact as far as the GPU is concerned the camera isn’t a thing that exists. The camera is effectively just a dummy object reference point used to calculate matrices which are to pass to the shaders which do the actual rendering. Everything looks consistent just by virtue of the fact every shader is passed the same view and projection matrices so they all line up in the end.
Well, more specifically, all your shaders would have to be custom, so there’s no problem!
I suspect what you’re actually complaining about is you can’t use shaders you get from the asset store or downloaded from someplace. It’s true you can’t use them unmodified, to do this you would have to hand modify all of them.
The only way I can think of to do what you want by purely modifying the camera component would be to use a skewed camera projection, which messes with a bunch of other stuff. The camera clipping plane will always be parallel to the view plane (ie: the “screen”), but if you asymetrically warp the projection matrix you can look “down” with out rotating the camera.
The issue is I am doing this a part of an Asset I will myself be publishing and it won’t be very versatile if users have to edit all of their shaders,
Perhaps is not called a shader for a camera but what I mean is sort of like post-image effects (e.g. colorisation, warp etc), I was wondering if I could clip the view there.
here is an example what I mean by the post-image effects
Image effects work on the image that was rendered. Basically anything you can do to a screenshot of a game in Gimp or Photoshop an image effect can do. You could certainly blank out pixels close to the camera along an arbitrary plane, but that won’t make things visible behind those pixels as that data isn’t available anymore, it’ll just let you set it to a flat color or maybe another texture. Certainly the inverse of this is how a lot of image effect based fog works, it draws a gradient color, or perhaps a copy of the skybox texture, over things as they get further away to make it appear as if the sky is showing through it, when in fact the sky is just being painted on top.
You can actually construct your own projection matrix and set it to the camera. The built-in Matrix4x4 class has a helper function to do that as well. What you want to do is to face the camera perpendicular to the plane you want to clip, then construct the view frustum based on the “window” that you want to look through.