Black pixels on depth mask

Hi,

I have tried to use depth mask and create a hole in plane using the following tutorial:

YOUTUBE:Unity Sort-of-Tutorial: Making Fake Holes

Shader "Masked/Mask" {
 
	SubShader {
		// Render the mask after regular geometry, but before masked geometry and
		// transparent things.
 
		Tags {"Queue" = "Geometry-1" }
 
		// Don't draw in the RGBA channels; just the depth buffer
 
		ColorMask 0
		ZWrite On
 
		// Do nothing specific in the pass:
 
		Pass {}
	}
}

The issue is that transparent plane is shown as black pixels in some android phones.

I have tested the hole in Samsung S7 and Huawei Mate 20 Pro and it is working fine but same apk will produce black pixels, e.g. Samsung Galaxy S9. I am worried that this will be common to many other phones as well.

Any solution on how to fix this. Is this a bug on unity or it is something else?

137399-hole.jpg

Picture on top is the correct one and the bottom is how it looks like on Samsung Galaxy S9.

I found other issues which looks a like:

User petermauger on the Vuforia forums posted a variant on the shader that worked on my android devices. https://developer.vuforia.com/forum/unity-extension-technical-discussion/issue-depth-mask-shader-dont-work-ar-unity3d

Shader "DepthMask" {
    SubShader {
        Tags { "RenderType"="Opaque" "Queue"="Geometry-1"}
        colormask 0
        Pass {
            Stencil {
                Ref 2
                Comp Greater
                Pass Replace
            }
    
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            struct appdata {
                float4 vertex : POSITION;
            };
            struct v2f {
                float4 pos : SV_POSITION;
            };
            v2f vert(appdata v) {
                v2f o;
                o.pos = UnityObjectToClipPos(v.vertex);
                return o;
            }
            half4 frag(v2f i) : SV_Target {
                return half4(1,0,0,1);
            }
            ENDCG
        }
    }
}

Suggestion: Try setting the “ZTest” flag to “Always” in the shader, it’s a problem my studio has faced in the past with certain devices

Hope that helps!

Figured it out, set the camera clear flags to depth only

[181736-解决.png|181736]Year 2021 here, It’s due to the default API in player settings of android is Vulkan, drag the OpenGLES 3 up to make it default API.
For those of older unity version and graphics APIs, I guess it’s also relative to graphics API bugs in unity, so try to change your graphics API might help