Hey! I need to redraw the same scene a couple of times with a different stencil mask clipping everything in the scene each time. All directly to screen on top the previous render; no render textures or post effects or any such thing involved. I would like to set up a global stencil test to apply to absolutely everything before each render.
A few options that you might have in mind that I cannot use and why:
- Custom pipeline: This is the only solution for which I’ve actually found a way in the documentation to directly set the stencil state, but I don’t have the time, experience or desire to go with this when all I want to do is hook into the standard pipeline and do one little thing, and I think we’re stuck on too old a version of Unity anyway.
- Shaders: I know that I can set up a stencil test in a shader, but I’m new on a project that’s already full of shaders, both regular and from ShaderForge, as well as ones that belong to various plugins such as MegaSplat, so I simply don’t have the level of control over the shaders used this project that I can just go in and edit all of them anyway. Thus I cannot use shader global variables, because that would entail modifying every shader to add a stencil test that reads it. I also cannot use replacement shaders because then I would have to reimplement every shader anyway.
-
Post effect: Some people seem to have misunderstood my question and suggested various things related to this. Not sure what’s wrong with my wording, but this has nothing to do with those, sorry.
If I was working on a pure OpenGL project I would just drop glStencilFunc() and glStencilOp() in there right before rendering the scene, so that’s basically how I would like to solve this in Unity too, if at all possible, whether that be by going through the camera’s OnPreRender() and OnPostRender() using some entry point in the Unity C# API to access the corresponding functions, or if I can somehow use command buffers to hook in there, but I haven’t find any such option for those in the documentation…
Thanks!