here is my code below:
Pass
{
Stencil
{
Ref[_MaterialID]
Comp Always
Pass Replace
}
Cull Back
ZWrite On
ZTest LEqual
CGPROGRAM
#include “UnityCG.cginc”
#pragma vertex vert
#pragma fragment frag
sampler2D _MainTex;
float4 _Color;
struct vertexInput
{
float4 vertex:POSITION;
};
struct vertexOutput
{
float4 pos:SV_POSITION;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
return output;
}
float4 frag(vertexOutput input):COLOR
{
return _Color;
}
ENDCG
}
Pass
{
Stencil
{
Ref[_MaterialID]
Comp NotEqual
}
ZWrite On
ZTest Greater
CGPROGRAM
#include “UnityCG.cginc”
#pragma vertex vert
#pragma fragment frag
float4 _OverlayColor;
struct vertexInput
{
float4 vertex:POSITION;
};
float4 vert(vertexInput input):SV_POSITION
{
return mul(UNITY_MATRIX_MVP, input.vertex);
}
struct fragOutput
{
float4 col:COLOR;
};
fragOutput frag(void)
{
fragOutput o;
o.col = _OverlayColor;
return o;
}
ENDCG
}
here everything works fine to me
but, when i add another Empty Pass at the Top, odd things happened.
the farther object’s overlay sillhouette just be replaced by the nearer object
i guss the neaer’s 2nd Pass(have added another Empty Pass, so it’s 2nd now) happened after the farther’s 3rd Pass, as for ZTest Pass, the color replaced