I’m working on an AR project (meta quest 3) where I generate ARPlanes. Each plane uses an occlusion shader, so AR content is hidden behind real-world geometry (like walls).
I want to use a StencilRevealShader that writes a specific ID to the stencil buffer. The idea is to use that ID with certain objects in my renderer, so I can “reveal” just a specific layer—think windows or doors.
The problem:
Right now, my occlusion shader appears even behind the stencil reveal shader. For example, if I have a window, I want to see through it—so the occlusion mesh (wall) should not be visible through the window. But currently, the wall (occlusion mesh) still shows up behind the stencil reveal. The objects that are supposed to be revealed are still occluded by the wall.
What I want:
The occlusion shader should only be visible in front of the stencil area, and should be disabled when it’s behind the stencil, so i can see objects on that layer, and not being hide by the occlusion mesh.
Shader "Custom/OcclusionbisShader"
{
SubShader
{
Tags {
"RenderType"="Opaque"
"Queue"="Geometry+1"
}
Pass
{
Name "OcclusionMask"
ZWrite On
ZTest LEqual
Blend One Zero
ColorMask 0
Stencil
{
Ref 0
Comp Equal
Pass Keep
Fail Keep
}
}
}
}```
```c++
Shader "Custom/StencilRevealShader"
{
Properties
{
[IntRange] _StencilID ("Stencil ID", Range(0, 255)) = 0
}
SubShader
{
Tags
{
"RenderType"="Transparent"
"Queue" = "Geometry"
}
Pass
{
Blend Zero One
ZWrite Off
Stencil
{
Ref [_StencilID]
Comp Always
Pass Replace
Fail Keep
}
}
}
}```