Thank you so much joaobsneto! Your are awesome. Your shader\material worked perfectly in Unity 5 and with Tango on Android. Super easy, and exactly what we are all looking for. They should add this to the Unity SDK!
I had an older 'CatchShadowOnly' shader that stopped working in Unity 2017. ShadowDrawer shader works great. I did have to set rendering to 'Forward' on the camera as well as the project. It works with multiple lights as well. Thanks for posting!
Wont work on Unity 2018 Shader error in 'Custom/ShadowDrawer': syntax error: unexpected token ';' at line 33 (on d3d11) Compiling Vertex program with UNITY_PASS_FORWARDADD POINT Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_RGBM_ENCODING
I'm getting the same error on Unity 2018. There seems to be something wrong with the color lerp. Code (CSharp): return half4(_Color.rgb, lerp(_Color.a, 0, atten)); Could anyone with a bit of shader code knowdledge have a look at this? Full shader is here: https://raw.githubusercontent.com/keijiro/ShadowDrawer/master/Assets/ShadowDrawer.shader
the https://github.com/keijiro/ShadowDrawer shader works like a charm in 2018 !!!! Tho it needs a drawn invisible mesh, it's just perfect !!! i wish unity includes this shader ( mebe optimized for the engine ) in standard shaders !!!!! It would be damn convenient for solving unity engine limitations.... errr.... For beein sure.... here is the code that works with unity 2018 ( just in case it disappears ) Code (CSharp): // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' Shader "Custom/ShadowDrawer" { Properties { _Color ("Shadow Color", Color) = (0, 0, 0, 0.6) } CGINCLUDE #include "UnityCG.cginc" #include "AutoLight.cginc" struct v2f_shadow { float4 pos : SV_POSITION; LIGHTING_COORDS(0, 1) }; half4 _Color; v2f_shadow vert_shadow(appdata_full v) { v2f_shadow o; o.pos = UnityObjectToClipPos(v.vertex); TRANSFER_VERTEX_TO_FRAGMENT(o); return o; } half4 frag_shadow(v2f_shadow IN) : SV_Target { half atten = LIGHT_ATTENUATION(IN); return half4(_Color.rgb, lerp(_Color.a, 0, atten)); } ENDCG SubShader { Tags { "Queue"="AlphaTest+49" } // Depth fill pass Pass { ColorMask 0 CGPROGRAM #pragma vertex vert #pragma fragment frag struct v2f { float4 pos : SV_POSITION; }; v2f vert(appdata_full v) { v2f o; o.pos = UnityObjectToClipPos (v.vertex); return o; } half4 frag(v2f IN) : SV_Target { return (half4)0; } ENDCG } // Forward base pass Pass { Tags { "LightMode" = "ForwardBase" } Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM #pragma vertex vert_shadow #pragma fragment frag_shadow #pragma multi_compile_fwdbase ENDCG } // Forward add pass Pass { Tags { "LightMode" = "ForwardAdd" } Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM #pragma vertex vert_shadow #pragma fragment frag_shadow #pragma multi_compile_fwdadd_fullshadows ENDCG } } FallBack "Mobile/VertexLit" }
requires forward, a bit limiting, but if that meets your needs its a blast. There is a dude that made a camera casting shadows, cna´t find the link now
Here the dr Frankenstein monster, it's works with point and spot lights sources, but I have no clue how, and I pretty sure "wpos" can be gotten from built in vars, but I also no clue XD Code (CSharp): Shader "Custom/ShadowDrawer" { Properties { _Color ("Shadow Color", Color) = (0, 0, 0, 0.6) _ShadowBoost("sShadow Boost", float) = 1.0 } CGINCLUDE #include "UnityCG.cginc" #include "AutoLight.cginc" struct v2f_shadow { float4 pos : SV_POSITION; LIGHTING_COORDS(0, 1) }; half4 _Color; v2f_shadow vert_shadow(appdata_full v) { v2f_shadow o; o.pos = UnityObjectToClipPos(v.vertex); TRANSFER_VERTEX_TO_FRAGMENT(o); return o; } half4 frag_shadow(v2f_shadow IN) : SV_Target { half atten = LIGHT_ATTENUATION(IN); return half4(_Color.rgb, lerp(_Color.a, 0, atten)); } ENDCG SubShader { Tags { "Queue"="AlphaTest+49" } // Depth fill pass Pass { ColorMask 0 CGPROGRAM #pragma vertex vert #pragma fragment frag struct v2f { float4 pos : SV_POSITION; }; v2f vert(appdata_full v) { v2f o; o.pos = UnityObjectToClipPos (v.vertex); return o; } half4 frag(v2f IN) : SV_Target { return (half4)0; } ENDCG } // Forward base pass Pass { Tags { "LightMode" = "ForwardBase" } Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM #pragma vertex vert_shadow #pragma fragment frag_shadow #pragma multi_compile_fwdbase ENDCG } Pass { Tags { "LightMode" = "ForwardAdd" } Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile_fwdadd_fullshadows #include "Lighting.cginc" #include "AutoLight.cginc" float _ShadowBoost; struct v2f { float4 pos : SV_POSITION; float4 wpos : TEXCOORD2; LIGHTING_COORDS(0,1) }; v2f vert (appdata_full v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.wpos = mul(unity_ObjectToWorld, v.vertex); TRANSFER_VERTEX_TO_FRAGMENT(o); return o; } float4 frag (v2f i) : COLOR { fixed shadow = UNITY_SHADOW_ATTENUATION(1, i.wpos); float atten = 1; #if defined (POINT) unityShadowCoord3 lightCoord = mul(unity_WorldToLight, unityShadowCoord4(i.wpos.xyz, 1)).xyz; atten = tex2D(_LightTexture0, dot(lightCoord, lightCoord).rr).r.UNITY_ATTEN_CHANNEL; atten*=_ShadowBoost; #elif defined (SPOT) float4 lightCoord = mul(unity_WorldToLight, float4(i.wpos.xyz, 1)); atten = (lightCoord.z > 0) * tex2D(_LightTexture0, lightCoord.xy / lightCoord.w + 0.5).w * tex2D(_LightTextureB0, dot(lightCoord, lightCoord).rr).UNITY_ATTEN_CHANNEL; #endif return float4(_Color.xyz, _Color.a*(1-shadow)*atten); } ENDCG } } FallBack "Mobile/VertexLit" }
Thats great! That is just what I am looking for, especially this last version that works with point light! You guys rock!