123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- Shader "Hidden/Shadow2DUnshadowSprite"
- {
- Properties
- {
- _MainTex ("Texture", 2D) = "white" {}
- _Color("Tint", Color) = (1,1,1,1)
- [HideInInspector] _ShadowColorMask("__ShadowColorMask", Int) = 0
- }
- SubShader
- {
- Tags { "RenderType" = "Transparent" }
-
- Pass
- {
- Stencil
- {
- Ref 1
- Comp Always
- Pass Replace
- }
-
- Cull Off
- Blend One One
- BlendOp Add
- ZWrite Off
- ZTest Always
-
- ColorMask GB // Clear the unshadow color (G), and set the sprite alpha (B)
-
- Name "Sprite Unshadow (GB) - Stencil: Ref 1, Comp Always, Pass Replace"
-
- HLSLPROGRAM
- #pragma vertex vert
- #pragma fragment frag
-
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
-
- struct Attributes
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- float4 color : COLOR;
- };
-
- struct Varyings
- {
- float4 vertex : SV_POSITION;
- float2 uv : TEXCOORD0;
- float4 color : COLOR;
- };
-
- sampler2D _MainTex;
- float4 _MainTex_ST;
- float4 _Color;
- float _ShadowAlphaCutoff;
-
- Varyings vert(Attributes v)
- {
- Varyings o;
- o.vertex = TransformObjectToHClip(v.vertex.xyz);
- o.uv = TRANSFORM_TEX(v.uv, _MainTex);
- o.color = _Color.a * v.color;
- return o;
- }
-
- half4 frag(Varyings i) : SV_Target
- {
- half4 main = i.color * tex2D(_MainTex, i.uv);
-
- if (main.a <= _ShadowAlphaCutoff)
- discard;
-
- return half4(0, 0, 0, 0);
- }
- ENDHLSL
- }
- // Remove stencil from previous stencil pass
- Pass
- {
- Stencil
- {
- Ref 0
- Comp Always
- Pass Replace
- }
-
- Blend One One
- BlendOp Add
- Cull Off
- ZWrite Off
- ZTest Always
-
- ColorMask B
-
- Name "Sprite Unshadow (B) - Stencil: Ref 0, Comp Always, Pass Replace"
-
- HLSLPROGRAM
- #pragma vertex vert
- #pragma fragment frag
-
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
-
- struct Attributes
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- float4 color : COLOR;
- };
-
- struct Varyings
- {
- float4 vertex : SV_POSITION;
- float2 uv : TEXCOORD0;
- float4 color : COLOR;
- };
-
- sampler2D _MainTex;
- float4 _MainTex_ST;
- float4 _Color;
- float _ShadowAlphaCutoff;
-
- Varyings vert(Attributes v)
- {
- Varyings o;
- o.vertex = TransformObjectToHClip(v.vertex.xyz);
- o.uv = TRANSFORM_TEX(v.uv, _MainTex);
- o.color = _Color.a * v.color;
- return o;
- }
-
- half4 frag(Varyings i) : SV_Target
- {
- half4 main = i.color * tex2D(_MainTex, i.uv);
-
- if (main.a <= _ShadowAlphaCutoff)
- discard;
-
- return half4(1,1,main.a,1);
- }
- ENDHLSL
- }
- }
- }
|