Hello,
I am working on a project where I intend to make use of Stencil-based Portals. I am currently using Unity 6.1 URP.
I do not wish to use a Render Texture for my approach, as the Stencil method has many advantages (namely performance).
My set-up currently uses two cameras - the main Base camera and the portal Overlay camera, while the Overlay is part of Base's stack.
I already have the movement and direction of the camera set-up correctly, and I only need to find a way to correctly apply the Overlay camera's output to the desired portal surface.
I am looking for either of these two solutions:
A) Have the Overlay camera capture the entire screen and using the stencil buffer render only where the stencil buffer is equal to desired value (meaning, the portal surface has a shader that sets stencil value to desired value)
B) Use the camera's output and use it as an input to a shader (applied on the portal surface) and scale it to the surface's UV (this works if using Asymmetrical projection), but without rendering to a texture (RenderTexture; if that is even possible).
I already have the method A) sort of working, however one major thing troubles me - for unknown reasons, the Overlay camera doesn't seem to write to the depth buffer at all, so geometry visible behind the portal is displaying in the portal as well.
For the method B), I am unsure whether it is possible to use the camera output in the shader without having to use a RenderTexture as intermediate step, which (at least to my understanding) could mean hurting performance.
Do you have any suggestions how to make this work in Unity or alternative approaches to this problem?
I'd be very thankful for any suggestions.