Is there a way to have a transparent diffuse object receive real time directional shadows? I have searched through the multiple forum threads, all saying it's really not practical/ possible to do. However what I am looking for is a decal shader that will be placed on a wall so it really just needs to allow the shadows underneath to read through. Can this be done more easily perhaps?
looking at the shader on the wiki http://wiki.unity3d.com/index.php?title=TransparentShadowReceiver I have found that by changing the Queue to Geometry+1 and adding "LightMode" = "ForwardBase" to the tags and fullforwardshadows to the #pragma a transparent decal gets shadows, like I need. However "LightMode" = "ForwardBase" is wrecks the lighting and everything becomes extremely bright and washed out . Any ideas, I just need the shadows to show through my transparent decal. Code (csharp): Shader "AlphaShadow" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("tex1", 2D) = "white" {} } SubShader { Tags { "Queue"="Geometry+1" "IgnoreProjector"="True" "RenderType"="Transparent" "LightMode" = "ForwardBase" } LOD 300 CGPROGRAM #pragma target 3.0 #pragma surface surf Lambert alpha fullforwardshadows sampler2D _MainTex; float4 _Color; struct Input { float2 uv_MainTex; fixed4 color: Color; }; void surf (Input IN, inout SurfaceOutput o) { fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); o.Albedo = tex.rgb ; o.Alpha = 1; } ENDCG } FallBack "Transparent/Cutout/VertexLit" }
Try this one (works with Forward rendering type and directional light only): Code (csharp): Shader "Transptest" { Properties { _MainTex("MainTex", 2D) = "black" {} _Cutoff("Cutoff", Range (0, 1))= 0.5 _MainColor("_MainColor", Color) = (1,1,1,1) } SubShader { Pass { Name "Caster" Tags { "LightMode" = "ShadowCaster" } Offset 1, 1 Fog {Mode Off} ZWrite On ZTest LEqual Cull Off Alphatest Greater [_Cutoff] CGPROGRAM #pragma vertex vert #pragma fragment frag addshadow #pragma multi_compile_shadowcaster #pragma fragmentoption ARB_precision_hint_fastest #include "UnityCG.cginc" struct v2f { V2F_SHADOW_CASTER; float2 uv : TEXCOORD1; }; uniform float4 _MainTex_ST; v2f vert( appdata_base v ) { v2f o; TRANSFER_SHADOW_CASTER(o) o.uv = TRANSFORM_TEX(v.texcoord, _MainTex); return o; } uniform sampler2D _MainTex; uniform fixed _Cutoff; uniform fixed4 _MainColor; float4 frag( v2f i ) : COLOR { fixed4 texcol = tex2D( _MainTex, i.uv ); clip( texcol.a*_MainColor.a - _Cutoff ); SHADOW_CASTER_FRAGMENT(i) } ENDCG } Tags { "Queue"="Geometry+500" "IgnoreProjector"="False" "RenderType"="Transparent" } Cull Off ZWrite On ZTest LEqual ColorMask RGBA Alphatest Greater [_Cutoff] Fog{ } CGPROGRAM #pragma surface surf BlinnPhongEditor vertex:vert #pragma target 3.0 sampler2D _MainTex; struct EditorSurfaceOutput { half3 Albedo; half3 Normal; half3 Emission; half3 Gloss; half Specular; half Alpha; half4 Custom; }; inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light) { half3 spec = light.a * s.Gloss; half4 c; c.rgb = (s.Albedo * light.rgb + light.rgb * spec); c.a = s.Alpha; return c; } inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten) { half3 h = normalize (lightDir + viewDir); half diff = max (0, dot ( lightDir, s.Normal )); float nh = max (0, dot (s.Normal, h)); float spec = pow (nh, s.Specular*128.0); half4 res; res.rgb = _LightColor0.rgb * diff; res.w = spec * Luminance (_LightColor0.rgb); res *= atten * 2.0; return LightingBlinnPhongEditor_PrePass( s, res ); } struct Input { float2 uv_MainTex; }; void vert (inout appdata_full v, out Input o) { float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0); float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0); float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0); float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0); } void surf (Input IN, inout EditorSurfaceOutput o) { o.Normal = float3(0.0,0.0,1.0); o.Alpha = 1.0; o.Albedo = 0.0; o.Emission = 0.0; o.Gloss = 0.0; o.Specular = 0.0; o.Custom = 0.0; float4 Tex2D0=tex2D(_MainTex,(IN.uv_MainTex.xyxy).xy); float4 Master0_1_NoInput = float4(0,0,1,1); float4 Master0_2_NoInput = float4(0,0,0,0); float4 Master0_3_NoInput = float4(0,0,0,0); float4 Master0_4_NoInput = float4(0,0,0,0); float4 Master0_7_NoInput = float4(0,0,0,0); float4 Master0_6_NoInput = float4(1,1,1,1); o.Albedo = Tex2D0; o.Alpha = Tex2D0.aaaa; o.Normal = normalize(o.Normal); } ENDCG } Fallback "Diffuse" } Btw, it works actually in case some other objects are background to the object by which material this shader is used.