Hi All! I’m struggling with a stencil setup. I will try to explain as simple as possible my situation.
I need to recreate the occlusion of invisible walls in Unity2021 URP Android VR.
I reach a point where Im stuck with the stencils and I believe I’m close to solve but still there is something Im missing.
As you can see in the image,
- I achieved what I need, to have a ground occluded by invisible walls, so the walls are masking the ground just revealing the ground as you would have with normal walls.
- I achieved also to have windows on the walls (holes) and the objects behind are only renderer through the window (see the red cube behind the window) and not through the invisible walls.
My problem is with the gray cube on the picture. As you can see on the game screen, even if is not behind the wall, the cube is occluded by the wall mask.
Setup:
I have two extra layers and two render features.
Layers:
- One for the masks called “Mask”
- Another one for the objects to be occluded called “SeeThrough”
This is my shader for the mask objects (walls):
Shader "Custom/UnlitMask"
{
Properties{}
SubShader{
Tags {
"RenderType" = "Opaque"
}
Pass {
ZWrite Off
}
}
}
This is the settings of my RP beofre the render features

My first Render Feature is turning on the mask pixels like this:

And this is my second render feature to bring back the occluded geometry

This is my pipeline Settings:

On my desesperation, I believe I tried using brute force every single possibility:
- before after rendering opaques, and may others
- Compare functions
- Pass, Fail and Z fail
- Single Instanced Pass
- Multiview / Multipass / Single Pass Instanced / Multipass
- Depth buffer on/off
Obbiously Im missing something in this stencil puzzle of options.
I would appreciate a bit of help from somene with a clear undertanding about stencils or any bright mind with another alternative.
Thanks!
