ShadowDrawer.shader 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. Shader "Custom/ShadowDrawer"
  2. {
  3. Properties
  4. {
  5. _Color ("Shadow Color", Color) = (0, 0, 0, 0.6)
  6. }
  7. CGINCLUDE
  8. #include "UnityCG.cginc"
  9. #include "AutoLight.cginc"
  10. struct v2f_shadow {
  11. float4 pos : SV_POSITION;
  12. float3 worldPos : TEXCOORD0;
  13. UNITY_LIGHTING_COORDS(1, 2)
  14. };
  15. half4 _Color;
  16. v2f_shadow vert_shadow(appdata_full v)
  17. {
  18. v2f_shadow o;
  19. UNITY_INITIALIZE_OUTPUT(v2f_shadow, o);
  20. o.pos = UnityObjectToClipPos(v.vertex);
  21. o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
  22. UNITY_TRANSFER_LIGHTING(o, v.texcoord1);
  23. return o;
  24. }
  25. half4 frag_shadow(v2f_shadow IN) : SV_Target
  26. {
  27. UNITY_LIGHT_ATTENUATION(atten, IN, IN.worldPos);
  28. return half4(_Color.rgb, lerp(_Color.a, 0, atten));
  29. }
  30. ENDCG
  31. SubShader
  32. {
  33. Tags { "Queue"="AlphaTest+49" }
  34. // Depth fill pass
  35. Pass
  36. {
  37. ColorMask 0
  38. CGPROGRAM
  39. #pragma vertex vert
  40. #pragma fragment frag
  41. struct v2f {
  42. float4 pos : SV_POSITION;
  43. };
  44. v2f vert(appdata_full v)
  45. {
  46. v2f o;
  47. o.pos = UnityObjectToClipPos(v.vertex);
  48. return o;
  49. }
  50. half4 frag(v2f IN) : SV_Target
  51. {
  52. return (half4)0;
  53. }
  54. ENDCG
  55. }
  56. // Forward base pass
  57. Pass
  58. {
  59. Tags { "LightMode" = "ForwardBase" }
  60. Blend SrcAlpha OneMinusSrcAlpha
  61. CGPROGRAM
  62. #pragma vertex vert_shadow
  63. #pragma fragment frag_shadow
  64. #pragma multi_compile_fwdbase
  65. ENDCG
  66. }
  67. // Forward add pass
  68. Pass
  69. {
  70. Tags { "LightMode" = "ForwardAdd" }
  71. Blend SrcAlpha OneMinusSrcAlpha
  72. CGPROGRAM
  73. #pragma vertex vert_shadow
  74. #pragma fragment frag_shadow
  75. #pragma multi_compile_fwdadd_fullshadows
  76. ENDCG
  77. }
  78. }
  79. FallBack "Mobile/VertexLit"
  80. }