A while back, there was a question on receiving shadows on semi-transparent decals:
This works great! As the objects are decals that always sit on top of solid surfaces, this workaround is really suitable.
Unfortuantely, this doesn’t work in deferred, the above image is Forward, the lower deferred.
I have tried to force the shader to render Forward, but it doesn’t seem to work correctly, leaving the black surface where the bounds of the mesh are (though it’s still semi transparent?)
The shader is as follows:
Shader "Project/DecalDiffuse"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_Emission("Emission", Color) = (0,0,0,0)
_MainTex ("Diffuse Texture", 2D) = "white" {}
}
SubShader
{
Tags
{
"RenderType" = "Transparent"
"IgnoreProjector" = "True"
"Queue" = "AlphaTest"
}
Tags { "LightMode" = "Vertex" }
LOD 200
CGPROGRAM
#pragma surface surf WrapLambert exclude_path:deferred decal:blend
half4 LightingWrapLambert (SurfaceOutput s, half3 lightDir, half atten)
{
half NdotL = dot (s.Normal, lightDir);
half diff = NdotL * 0.5 + 0.5;
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten);
c.a = s.Alpha;
return c;
}
struct Input
{
float2 uv_MainTex;
half4 color : COLOR;
};
sampler2D _MainTex;
fixed4 _Color;
fixed4 _Emission;
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb * IN.color.rgb;
o.Alpha = c.a * IN.color.a;
o.Emission = _Emission;
}
ENDCG
}
FallBack "Transparent/Cutout/Diffuse"
}
The strength of this black square seems to be that of a shadow at full strength, but it does not respond to the sun shadow strength slider.
I presume this is rendering at some random point in the deferred pass where the lighting hasn’t been properly applied yet?