Ok, so the thing I’m trying to make is making unit visible through solid objects.
I write simple shader (I remove all unnecessary):
SubShader code
SubShader {
Tags { "RenderType"="Opaque" "Queue" = "Geometry+1"}
LOD 200
Cull Back
ZWrite Off
ZTest Always
CGPROGRAM
#pragma surface surf Overlap decal:blend
#pragma target 3.0
sampler2D _OverlapText;
half4 _OverlapColor;
struct Input {
float2 uv_MainTex;
};
half4 LightingOverlap(SurfaceOutput o, half3 lightDir, half3 viewDir, half atten)
{
half3 returnColor = o.Albedo;
return half4(returnColor, o.Alpha);
}
half4 LightingOverlap_PrePass(SurfaceOutput o, half4 light)
{
fixed4 c;
c.rgb = o.Albedo;
c.a = o.Alpha;
return c;
}
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_OverlapText, IN.uv_MainTex);
o.Albedo = c.rgb * _OverlapColor.rgb;
o.Alpha = c.a * _OverlapColor.a;
}
ENDCG
Cull Off
ZWrite on
ZTest LEqual
CGPROGRAM
#pragma surface surf Lambert
#pragma target 3.0
struct Input {
half2 uv_MainTex;
half3 viewDir;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb * _Color.rgb;
o.Alpha = _Color.a * c.a;
}
ENDCG
}
That’s what the goal looks like in forward renderer:
Thats fine! (Cubes queue is set to “Geometry”)
Than I add another character:
Thats fine too! Spidys don’t show through each other.
But when using deferred renderer shader is behaving unpredictably.
For example I set to Cubes are same shader (“Geometry+1”). And I see Spider Man number one throw Spider Man number two (it’s wrong), but i dont see them throw cubes:
It looks to act completely random. What I’am doing wrong?
P.S. There is a chance that problem is due to the faulty Spidy model, since none of standart cubes or spheres were shown through each other with this shader.