- Home /
having a camera render an object only if it appears after a plane
Hi,
I am attempting to make a portal effect using render textures and a secondary camera and I'm running into a bit of an issue. Essentially, I have it all set up where the second camera matches the main camera's position relative to the portal object, which is then rendered onto a plane and such. Fairly simple stuff right now. The problem is when an object may exist between the portal exit and secondary camera, it's rendered onto the portal plane, breaking the illusion. I'm still new to the whole shader stuff, so forgive me if this is something super easy, but what I was wondering is if there's a way to have a camera not render any objects that would appear between the portal exit and itself?
Essentially having a sort of distance check to each thing the camera renders, or maybe even checking if it's within the viewing window of the portal exit and the camera? I think I've seen stencil shaders do a similar thing, but they apply to objects themselves as opposed to a camera which seems to be a bit better for my situation considering the two cameras should renderer things a bit differently.
Thanks for any help!
Answer by michi_b · Mar 20, 2019 at 06:44 AM
One thing you could certainly do is to test the world position of fragments against that plane in your shaders and use the clip() function to omit them if they fail it. But this would need a modification of all the shaders you are using. If you go that route I guess you could then use the OnPreRender callback to distinctively set those plane parameters for all you shaders per camera using the Shader.SetGlobalXY() methods.
Your answer
Follow this Question
Related Questions
Semi transparent Object behind walls? 1 Answer
Rendering Depth Correctly With Multiple Cameras 0 Answers
Is it possible to render a solid color where the Camera clips to the Near Clipping Plane? 1 Answer
Is there any way to hide only part of an object from the camera? (unity free) 2 Answers
occlusion culling conflict with shader,Occlusion culling conflict with shader 0 Answers