I have a problem with rendering shaders. I wrote 3 shaders to create a subtraction effect: Subtractor, Platform, Slice.
Subtractor
Shader "Custom/Subtractor_Shader"
{
SubShader
{
Tags { "RenderType"="Opaque" "Queue" = "Geometry-1"}
ZWrite off
Stencil
{
Ref 255
ReadMask 3
WriteMask 2
Comp notequal
Pass replace
}
Pass
{
Cull Front
ColorMask 0
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): COLOR
{
return half4(0,1,0,1);
}
ENDCG
}
}
}
Platform
Shader "Mobile/Fog_shader"
{
Properties
{
...
}
SubShader
{
Tags{"Queue"="Geometry"}
Fog{ Mode off }
LOD 200
Stencil
{
ref 255
ReadMask 2
WriteMask 3
Comp notequal
Pass replace
}
Pass
{
...
}
}
Fallback "Mobile/VertexLit"
}
Slice
Shader "Custom/Slice"
{
SubShader
{
Tags { "RenderType"="Opaque" "Queue" = "Geometry+1"}
Stencil
{
Ref 255
ReadMask 3
WriteMask 3
Comp equal
Pass keep
}
Pass
{
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): COLOR
{
return half4(1,0,1,1);
}
ENDCG
}
}
}
According to my idea, the Slice should be on top of the Subtractor, but the opposite happens.
What I want:
What I see:
I changed the values of different shaders for Readmask and WriteMask, but it didn't help