Stencil Buffer on Android

I’m not having any luck getting some shaders using the stencil buffer (for stencil masking) to work on Android. I’ve tried a couple different devices (HTC 626 and Samsung S7) and the geometry with said shader simply doesn’t render. I’ve checked and made sure “Disable Depth and Stencil” isn’t on. It works fine on PC/iOS.

Anybody have any luck with stencils on Android?

Did you check the logcat output for errors?

Yeah, nothing weird is showing up in logcat. It did confirm that my device has “GL_OES_packed_depth_stencil” though.

Any other ideas?

Please submit a bug report, we will check it.

Never mind me, figured out it wasn’t the stencil buffer causing issue but Android’s handling of z-depth. In the vertex shader I was doing:

#if defined(UNITY_REVERSED_Z)
o.pos.z = 0;
#else
o.pos.z = 1;
#endif

But for that 2nd case I should’ve been doing:

o.pos.z = o.pos.w;

Hey, i’m also trying to make stencil shader work in android but for some reason it doesn’t. I’m writing a standard surface shader with stencil, how do i fix the z-depth in that one?

Sorry, I don’t know enough about shaders to help very much. I can say that I had 2 shaders, the stencilMask and the stencilGeometry shader. The stencilGeometry shader would probably be your standard surface shader. But it was in the stencilMask shader that I added the above code, in the vert function. Here’s mine:

            v2f vert(appdata v)
            {
                v2f o;
                o.pos = UnityObjectToClipPos(v.vertex);
                //clear the depth buffer by setting Z to the far plane
                #if defined(UNITY_REVERSED_Z)
                o.pos.z = 0;
                #else
                o.pos.z = o.pos.w;
                #endif
                return o;
            }