I want to ensure that behind a semitransparent object no other transparent object is rendered. Therefore I’m doing one pass in the opaque pass with culling the front and setting the colormask to 0. In the Scene view my idea works, in the game view and in builds im Getting a black background where the skybox should be.
The shader code is really simple:
Shader "Custom/FillDepthBackFaces"
{
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="AlphaTest" }
ColorMask 0
Pass
{
ZWrite On
Cull Front
ZTest Less
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 = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
half4 frag(v2f i) : COLOR
{
return fixed4(1,0,0,1);
}
ENDCG
}
}
}
I’m getting this result:
The black box should be the skybox with the transparent layer on top. I guess the black area is kind of an optimization because in theory there would be no need to render a skybox behind opaque objects?!
Any ideas how to solve this?