Hi
The shaders are custom, written by ourselves as part of the project. The actual shaders are quite complex, but I've attached below simplified versions that demonstrate the same issue. UnlitStencil draws an object in blue with stencil set to 1; StencilMask should cause any renderer to mask the previous object when occupying the same pixels. This works fine in the editor scene view, and on device with single-pass off, but with single-pass on, no mask effect is seen, as if the stencil buffer is being ignored. Thanks for the help!
Shader "UnlitStencil"{ SubShader { Tags { "RenderType"="Opaque" } Stencil { Ref 1 Comp NotEqual Pass Keep Fail Keep } Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag struct appdata { float4 vertex : POSITION; }; struct v2f { float4 vertex : SV_POSITION; }; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); return o; } fixed4 frag (v2f i) : SV_Target { return half4(0, 0, 1, 1); } ENDCG } }}
Shader "StencilMask"{ SubShader { Tags { "RenderType"="Opaque" "Queue"="Geometry-100"} ColorMask 0 ZWrite Off Stencil { Ref 1 Comp Always Pass Replace } Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag struct appdata { float4 vertex : POSITION; }; struct v2f { float4 vertex : SV_POSITION; }; v2f vert(appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); return o; } half4 frag(v2f i) : COLOR { return 0; } ENDCG } }}