So, I’m making my first foray into Unity’s SRP, and I want to start this post off by saying how difficult I’m finding it to learn/understand. Maybe it’s just me, but I find the documentation to be incredibly patchy. Some functions are only documented at https://docs.unity3d.com/6000.0, while others can only be found at | Universal RP | 17.0.4. Hardly any of the functions contain usage examples, and worse still if I dare to search for something on google (rather than the just searching in the documentation) most results are for old documentation that is now outdated. So can people suggest some resources for learning the inns and outs of unity’s SRP, that isn’t just calling Blit passes? (as shown in their ‘example’ Unity - Manual: Example of a complete Scriptable Renderer Feature in URP)
Now, as for the what I’m trying to do specifically: I want to create a sort of ‘looking glass’ effect, where the world can only be viewed when looking through specific objects. Some initial research pointed me to the use of stencil rendering, and I was able to get reasonably close to the effect I wanted with a stencil shader, and a default Render Objects render feature
However, the main problem I encountered doing this, is that depth is not taken into account, and as such, objects infront of the ‘looking-glass’ object, will also be visible. (See below)
To attempt to fix this I tried also adding the looking glass objects to a Render Objects Feature, and enabling a depth test on the second.
This almost works as intended, but sometimes the floor likes to display infront of the other objects, and the skybox shows up grey, instead of the intended black colour.
So, as far as I can tell, the correct way to do this, is with a custom renderer feature that runs two passes - A first, only for my ‘looking glass’ objects, that writes to the stencil and depth buffers, and a second, for everything else. This second pass only renders geometry that passes a ‘greater-than’ depth test, and an ‘equals’ stencil test. (Am I missing anything here?)
However, I can’t seem to find ANY reference in the documentation on how to go about adding a stencil or depth test into the render pass.
I found through another forum post what appears to be unity’s implementation of the RenderObjects pass Graphics/Packages/com.unity.render-pipelines.universal/Runtime/Passes/RenderObjectsPass.cs at bbf120287c6e40398e20bba03d4069f934acb3dc · Unity-Technologies/Graphics · GitHub
But the SetStencilState function appears to be unused? presumably it’s called elsewhere, I guess in the Renderer feature, which I was unable to find.
So, how do I go about achieving what I want? Am I even going in the right direction, or am I barking up the wrong tree? Any and all suggestions / comments are really appreciated.




