Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Shadow2D-Projected.shader 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. Blend One One, One One
  13. ZWrite Off
  14. ZTest Always
  15. // This pass draws the projected shadows
  16. Pass
  17. {
  18. Name "Projected Shadow (R)"
  19. // Draw the shadow
  20. ColorMask R
  21. HLSLPROGRAM
  22. #pragma vertex vert
  23. #pragma fragment frag
  24. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  25. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/ShadowProjectVertex.hlsl"
  26. TEXTURE2D(_FalloffLookup);
  27. SAMPLER(sampler_FalloffLookup);
  28. half _ShadowSoftnessFalloffIntensity;
  29. Varyings vert (Attributes v)
  30. {
  31. return ProjectShadow(v);
  32. }
  33. half4 frag(Varyings i) : SV_Target
  34. {
  35. half2 mappedUV;
  36. float clamppedY = clamp(i.shadow.y, MIN_SHADOW_Y, 1);
  37. float value = 1.0f - saturate(abs(i.shadow.x) / clamppedY);
  38. mappedUV.x = value;
  39. mappedUV.y = _ShadowSoftnessFalloffIntensity;
  40. value = SAMPLE_TEXTURE2D(_FalloffLookup, sampler_FalloffLookup, mappedUV).r;
  41. half4 color = half4(value, value, value, value);
  42. return color;
  43. }
  44. ENDHLSL
  45. }
  46. // This pass draws the projected unshadowing
  47. Pass
  48. {
  49. Stencil
  50. {
  51. Ref 1
  52. Comp Equal
  53. Pass Keep
  54. }
  55. Name "Projected Unshadow (R) - Stencil: Ref 1, Comp Eq, Pass Keep"
  56. // Draw the shadow
  57. ColorMask G
  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. TEXTURE2D(_FalloffLookup);
  64. SAMPLER(sampler_FalloffLookup);
  65. half _ShadowSoftnessFalloffIntensity;
  66. Varyings vert (Attributes v)
  67. {
  68. return ProjectShadow(v);
  69. }
  70. half4 frag(Varyings i) : SV_Target
  71. {
  72. half2 mappedUV;
  73. float clamppedY = clamp(i.shadow.y, MIN_SHADOW_Y, 1);
  74. float value = 1.0f - saturate(abs(i.shadow.x) / clamppedY);
  75. mappedUV.x = value;
  76. mappedUV.y = _ShadowSoftnessFalloffIntensity;
  77. value = SAMPLE_TEXTURE2D(_FalloffLookup, sampler_FalloffLookup, mappedUV).r;
  78. half4 color = half4(value, value, value, value);
  79. return color;
  80. }
  81. ENDHLSL
  82. }
  83. }
  84. }