- Home /
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?
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:
Answer by screelman · Aug 08, 2019 at 07:23 AM
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
}
}
}
works perfect on 2020.3.17f as long as you remove vulkan
Answer by georgelewising · Aug 07, 2019 at 04:44 PM
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!
Answer by Pubesco · Dec 10, 2020 at 11:41 AM
Figured it out, set the camera clear flags to depth only
Answer by gamefish · Jun 06, 2021 at 11:05 AM
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
Your answer
Follow this Question
Related Questions
Terrain is pixelated 1 Answer
Spritesheet with multiple type is offset by one pixel 0 Answers
UV issue on pixel pallet from Blender 0 Answers
Pixel-perfect (Experimental) in URP does not upscale the texture 0 Answers
How I do a Pixel Distort Shader 0 Answers