Ei kuvausta
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-Unshadow-Sprite.shader 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. Shader "Hidden/Shadow2DUnshadowSprite"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "white" {}
  6. _Color("Tint", Color) = (1,1,1,1)
  7. [HideInInspector] _ShadowColorMask("__ShadowColorMask", Int) = 0
  8. }
  9. SubShader
  10. {
  11. Tags { "RenderType" = "Transparent" }
  12. Pass
  13. {
  14. Stencil
  15. {
  16. Ref 1
  17. Comp Always
  18. Pass Replace
  19. }
  20. Cull Off
  21. Blend One One
  22. BlendOp Add
  23. ZWrite Off
  24. ZTest Always
  25. ColorMask GB // Clear the unshadow color (G), and set the sprite alpha (B)
  26. Name "Sprite Unshadow (GB) - Stencil: Ref 1, Comp Always, Pass Replace"
  27. HLSLPROGRAM
  28. #pragma vertex vert
  29. #pragma fragment frag
  30. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  31. struct Attributes
  32. {
  33. float4 vertex : POSITION;
  34. float2 uv : TEXCOORD0;
  35. float4 color : COLOR;
  36. };
  37. struct Varyings
  38. {
  39. float4 vertex : SV_POSITION;
  40. float2 uv : TEXCOORD0;
  41. float4 color : COLOR;
  42. };
  43. sampler2D _MainTex;
  44. float4 _MainTex_ST;
  45. float4 _Color;
  46. float _ShadowAlphaCutoff;
  47. Varyings vert(Attributes v)
  48. {
  49. Varyings o;
  50. o.vertex = TransformObjectToHClip(v.vertex.xyz);
  51. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  52. o.color = _Color.a * v.color;
  53. return o;
  54. }
  55. half4 frag(Varyings i) : SV_Target
  56. {
  57. half4 main = i.color * tex2D(_MainTex, i.uv);
  58. if (main.a <= _ShadowAlphaCutoff)
  59. discard;
  60. return half4(0, 0, 0, 0);
  61. }
  62. ENDHLSL
  63. }
  64. // Remove stencil from previous stencil pass
  65. Pass
  66. {
  67. Stencil
  68. {
  69. Ref 0
  70. Comp Always
  71. Pass Replace
  72. }
  73. Blend One One
  74. BlendOp Add
  75. Cull Off
  76. ZWrite Off
  77. ZTest Always
  78. ColorMask B
  79. Name "Sprite Unshadow (B) - Stencil: Ref 0, Comp Always, Pass Replace"
  80. HLSLPROGRAM
  81. #pragma vertex vert
  82. #pragma fragment frag
  83. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  84. struct Attributes
  85. {
  86. float4 vertex : POSITION;
  87. float2 uv : TEXCOORD0;
  88. float4 color : COLOR;
  89. };
  90. struct Varyings
  91. {
  92. float4 vertex : SV_POSITION;
  93. float2 uv : TEXCOORD0;
  94. float4 color : COLOR;
  95. };
  96. sampler2D _MainTex;
  97. float4 _MainTex_ST;
  98. float4 _Color;
  99. float _ShadowAlphaCutoff;
  100. Varyings vert(Attributes v)
  101. {
  102. Varyings o;
  103. o.vertex = TransformObjectToHClip(v.vertex.xyz);
  104. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  105. o.color = _Color.a * v.color;
  106. return o;
  107. }
  108. half4 frag(Varyings i) : SV_Target
  109. {
  110. half4 main = i.color * tex2D(_MainTex, i.uv);
  111. if (main.a <= _ShadowAlphaCutoff)
  112. discard;
  113. return half4(1,1,main.a,1);
  114. }
  115. ENDHLSL
  116. }
  117. }
  118. }