Shader "BriarQueen/UI/Menu Selection Brush" { Properties { [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} _Color ("Tint", Color) = (0.02, 0.018, 0.015, 0.86) _Reveal ("Reveal", Range(0, 1)) = 1 _RevealSoftness ("Reveal Softness", Range(0.001, 0.35)) = 0.08 _EdgeFade ("Edge Fade", Range(0.001, 0.35)) = 0.12 _EndFade ("End Fade", Range(0.001, 0.35)) = 0.08 _NoiseStrength ("Noise Strength", Range(0, 1)) = 0.18 _NoiseScale ("Noise Scale", Range(1, 80)) = 24 _StreakStrength ("Streak Strength", Range(0, 1)) = 0.22 _StreakScale ("Streak Scale", Range(1, 80)) = 18 _StencilComp ("Stencil Comparison", Float) = 8 _Stencil ("Stencil ID", Float) = 0 _StencilOp ("Stencil Operation", Float) = 0 _StencilWriteMask ("Stencil Write Mask", Float) = 255 _StencilReadMask ("Stencil Read Mask", Float) = 255 _ColorMask ("Color Mask", Float) = 15 [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0 } SubShader { Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" "CanUseSpriteAtlas" = "True" } Stencil { Ref [_Stencil] Comp [_StencilComp] Pass [_StencilOp] ReadMask [_StencilReadMask] WriteMask [_StencilWriteMask] } Cull Off Lighting Off ZWrite Off ZTest [unity_GUIZTestMode] Blend SrcAlpha OneMinusSrcAlpha ColorMask [_ColorMask] Pass { Name "Default" CGPROGRAM #pragma vertex Vert #pragma fragment Frag #pragma target 2.0 #include "UnityCG.cginc" #include "UnityUI.cginc" #pragma multi_compile_local _ UNITY_UI_CLIP_RECT #pragma multi_compile_local _ UNITY_UI_ALPHACLIP struct AppData { float4 vertex : POSITION; float4 color : COLOR; float2 texcoord : TEXCOORD0; UNITY_VERTEX_INPUT_INSTANCE_ID }; struct Varyings { float4 vertex : SV_POSITION; fixed4 color : COLOR; float2 uv : TEXCOORD0; float4 worldPosition : TEXCOORD1; UNITY_VERTEX_OUTPUT_STEREO }; sampler2D _MainTex; fixed4 _Color; fixed4 _TextureSampleAdd; float4 _ClipRect; float _Reveal; float _RevealSoftness; float _EdgeFade; float _EndFade; float _NoiseStrength; float _NoiseScale; float _StreakStrength; float _StreakScale; float Hash21(float2 p) { p = frac(p * float2(123.34, 345.45)); p += dot(p, p + 34.345); return frac(p.x * p.y); } float ValueNoise(float2 uv) { float2 i = floor(uv); float2 f = frac(uv); float2 u = f * f * (3.0 - 2.0 * f); float a = Hash21(i); float b = Hash21(i + float2(1.0, 0.0)); float c = Hash21(i + float2(0.0, 1.0)); float d = Hash21(i + float2(1.0, 1.0)); return lerp(lerp(a, b, u.x), lerp(c, d, u.x), u.y); } Varyings Vert(AppData input) { Varyings output; UNITY_SETUP_INSTANCE_ID(input); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); output.worldPosition = input.vertex; output.vertex = UnityObjectToClipPos(input.vertex); output.uv = input.texcoord; output.color = input.color * _Color; return output; } fixed4 Frag(Varyings input) : SV_Target { fixed4 color = (tex2D(_MainTex, input.uv) + _TextureSampleAdd) * input.color; float reveal = saturate(_Reveal); float halfWidth = reveal * 0.5; float distFromCenter = abs(input.uv.x - 0.5); float revealMask = 1.0 - smoothstep(halfWidth, halfWidth + _RevealSoftness, distFromCenter); revealMask *= smoothstep(0.0, 0.02, reveal); float verticalFade = smoothstep(0.0, _EdgeFade, input.uv.y) * (1.0 - smoothstep(1.0 - _EdgeFade, 1.0, input.uv.y)); float endFade = smoothstep(0.0, _EndFade, input.uv.x) * (1.0 - smoothstep(1.0 - _EndFade, 1.0, input.uv.x)); float noise = ValueNoise(input.uv * _NoiseScale); float streak = ValueNoise(float2(input.uv.x * _StreakScale, input.uv.y * 3.0)); float surface = 1.0 - (noise * _NoiseStrength) - (streak * _StreakStrength); color.a *= revealMask * verticalFade * endFade * saturate(surface); #ifdef UNITY_UI_CLIP_RECT color.a *= UnityGet2DClipping(input.worldPosition.xy, _ClipRect); #endif #ifdef UNITY_UI_ALPHACLIP clip(color.a - 0.001); #endif return color; } ENDCG } } }