Shadow2D-Projected.shader 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. Shader "Hidden/ShadowProjected2D"
  2. {
  3. Properties
  4. {
  5. [HideInInspector] _ShadowColorMask("__ShadowColorMask", Float) = 0
  6. }
  7. SubShader
  8. {
  9. Tags { "RenderType"="Transparent" }
  10. Cull Off
  11. BlendOp Add
  12. ZWrite Off
  13. ZTest Always
  14. // This pass draws the projected shadow and sets the composite shadow bit.
  15. Pass
  16. {
  17. // Bit 0: Composite Shadow Bit, Bit 1: Global Shadow Bit
  18. Stencil
  19. {
  20. Ref 5
  21. ReadMask 4
  22. WriteMask 1
  23. Comp NotEqual
  24. Pass Replace
  25. Fail Keep
  26. }
  27. ColorMask [_ShadowColorMask]
  28. HLSLPROGRAM
  29. #pragma vertex vert
  30. #pragma fragment frag
  31. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  32. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/ShadowProjectVertex.hlsl"
  33. Varyings vert (Attributes v)
  34. {
  35. return ProjectShadow(v);
  36. }
  37. half4 frag (Varyings i) : SV_Target
  38. {
  39. return half4(1,1,1,1);
  40. }
  41. ENDHLSL
  42. }
  43. // Sets the global shadow bit, and clears the composite shadow bit
  44. Pass
  45. {
  46. // Bit 0: Composite Shadow Bit, Bit 1: Global Shadow Bit
  47. Stencil
  48. {
  49. Ref 3
  50. WriteMask 2
  51. ReadMask 1
  52. Comp Equal
  53. Pass Replace
  54. Fail Keep
  55. }
  56. // We only want to change the stencil value in this pass
  57. ColorMask 0
  58. HLSLPROGRAM
  59. #pragma vertex vert
  60. #pragma fragment frag
  61. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  62. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/ShadowProjectVertex.hlsl"
  63. Varyings vert (Attributes v)
  64. {
  65. return ProjectShadow(v);
  66. }
  67. half4 frag (Varyings i) : SV_Target
  68. {
  69. return half4(1,1,1,1);
  70. }
  71. ENDHLSL
  72. }
  73. }
  74. }