- Home /
Stencil buffer custom usage with deferred lighting?
I need to use stencil buffer for some simple clipping (front faces that passed ztest increase stencil, back faces that passed ztest decrease it)...
Setting stencil:
Tags { "RenderType"="Opaque" "Queue"="Geometry+10"}
ColorMask 0
ZTest LEqual
ZWrite off
Lighting off
Pass {
Cull Back
Stencil {
Pass IncrSat
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
Pass {
Cull Front
Stencil {
Pass DecrSat
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
using it later:
Tags { "RenderType" = "Opaque" "Queue"="Geometry+12" }
Stencil {
Ref 1
Comp GEqual
Pass Keep
}
However it looks like it's not really working with deferred (it only works with Ref 1, Pass replace, which is unusable because I can have overlapping areas that need to set stencil).
What mask can I use in deferred, what bits are not used/cleared, etc.?
Every example I can find is probably only for Forward... Documentation (link text) is very vague at best.
Any help/insight appreciated!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613140545im_/https://answers.unity.com/themes/thub/images/avi.jpg)