Hi,
I am trying to set up a shader which writes to the depthmask at a second pass (since I want the depth of the object written before it). However this seems to cause problems.
It seems as there is some fundamental drawing order of the passes, which I would like to alter if that is possible.
One can reproduce the scenario with the shader below, applying it to an object and duplicating that object. The Z sorting will not work right when overlapping the two objects.
Shader "Custom/ZWriteTest" {
Properties {
}
SubShader {
LOD 200
Pass {
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float3 color : COLOR0;
};
v2f vert (appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.color = v.normal * 0.5 + 0.5;
return o;
}
half4 frag (v2f i) : COLOR
{
return half4 (i.color, 1);
}
ENDCG
}
Pass {
ZWrite On
ColorMask 0
}
}
FallBack Off
}
Can anyone explain this and/or help me out?