Shader "Bansonic/Sprite Vertical Glow Only" { Properties { [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} [HideInInspector] _Color ("Tint", Color) = (1,1,1,1) [HideInInspector] PixelSnap ("Pixel snap", Float) = 0 [HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1) [HideInInspector] _AlphaTex ("External Alpha", 2D) = "white" {} [HideInInspector] _EnableExternalAlpha ("Enable External Alpha", Float) = 0 [HDR]_GlowColor ("Glow Color", Color) = (0.75,0.95,1,1) _Threshold ("Alpha Threshold", Range(0, 1)) = 0.08 _Intensity ("Glow Intensity", Range(0, 12)) = 3 _GlowRadius ("Edge Radius (Texels)", Range(0, 24)) = 4 _ExpandX ("Horizontal Expand", Range(0, 1)) = 0.08 _ExpandYBottom ("Bottom Expand", Range(0, 1)) = 0.03 _ExpandYTop ("Top Expand", Range(0, 6)) = 2.2 _VerticalStart ("Vertical Start", Range(0, 1)) = 0.1 _BottomFade ("Bottom Fade", Range(0, 1)) = 0.15 _CoreSuppress ("Core Suppress", Range(0, 1)) = 0.75 _SidePower ("Side Power", Range(0.5, 6)) = 1.8 _TopPower ("Top Power", Range(0.5, 6)) = 2.0 } SubShader { Tags { "Queue" = "Transparent" "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" "CanUseSpriteAtlas" = "True" } Cull Off ZWrite Off Blend One One Pass { Tags { "LightMode" = "Universal2D" } HLSLPROGRAM #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/Core2D.hlsl" #pragma vertex vert #pragma fragment frag #pragma target 2.0 #pragma multi_compile_instancing #pragma multi_compile _ SKINNED_SPRITE struct Attributes { float3 positionOS : POSITION; float4 color : COLOR; float2 uv : TEXCOORD0; UNITY_SKINNED_VERTEX_INPUTS UNITY_VERTEX_INPUT_INSTANCE_ID }; struct Varyings { float4 positionCS : SV_POSITION; half4 color : COLOR; float2 uv : TEXCOORD0; UNITY_VERTEX_OUTPUT_STEREO }; TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex); float4 _MainTex_TexelSize; CBUFFER_START(UnityPerMaterial) half4 _Color; half4 _GlowColor; half _Threshold; half _Intensity; half _GlowRadius; half _ExpandX; half _ExpandYBottom; half _ExpandYTop; half _VerticalStart; half _BottomFade; half _CoreSuppress; half _SidePower; half _TopPower; CBUFFER_END Varyings vert(Attributes input) { Varyings output = (Varyings)0; UNITY_SETUP_INSTANCE_ID(input); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); UNITY_SKINNED_VERTEX_COMPUTE(input); SetUpSpriteInstanceProperties(); input.positionOS = UnityFlipSprite(input.positionOS, unity_SpriteProps.xy); float2 uv = input.uv; float2 sign2 = float2(uv.x < 0.5 ? -1.0 : 1.0, uv.y < 0.5 ? -1.0 : 1.0); float yExpand = lerp((float)_ExpandYBottom, (float)_ExpandYTop, uv.y); input.positionOS.xy += float2(sign2.x * _ExpandX, sign2.y * yExpand); output.positionCS = TransformObjectToHClip(input.positionOS); output.uv = uv; output.color = input.color * _Color * unity_SpriteColor; return output; } float SampleAlpha(float2 uv, half4 tint) { half4 c = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv) * tint; return saturate((c.a - _Threshold) / max(1e-4, 1.0 - _Threshold)); } float EdgeField(float2 uv, half4 tint) { float2 texel = _MainTex_TexelSize.xy * max((float)_GlowRadius, 0.0001); float c = SampleAlpha(uv, tint); float n = SampleAlpha(uv + texel * float2(0, 1), tint); float s = SampleAlpha(uv + texel * float2(0, -1), tint); float e = SampleAlpha(uv + texel * float2(1, 0), tint); float w = SampleAlpha(uv + texel * float2(-1, 0), tint); float ne = SampleAlpha(uv + texel * float2(1, 1), tint); float nw = SampleAlpha(uv + texel * float2(-1, 1), tint); float se = SampleAlpha(uv + texel * float2(1, -1), tint); float sw = SampleAlpha(uv + texel * float2(-1, -1), tint); float dilated = max(max(max(n, s), max(e, w)), max(max(ne, nw), max(se, sw))); return saturate(dilated - c); } half4 frag(Varyings input) : SV_Target { half4 tint = input.color; float a = SampleAlpha(input.uv, tint); float edge = EdgeField(input.uv, tint); float side = smoothstep(0.30, 0.50, abs(input.uv.x - 0.5) * 2.0); float vertical = smoothstep(_VerticalStart, 1.0, input.uv.y); float top = pow(saturate(input.uv.y), _TopPower); float bottomFade = lerp(1.0, _BottomFade, saturate(1.0 - input.uv.y)); float glowMask = max(edge * 2.5, side * vertical * top); glowMask *= bottomFade; glowMask *= (1.0 - a * _CoreSuppress); half alpha = saturate(glowMask * _Intensity); half3 rgb = _GlowColor.rgb * alpha * _GlowColor.a; return half4(rgb, alpha); } ENDHLSL } } }