// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' Shader "Unlit/LightEffect" { Properties { _MainTex("Base (RGB)", 2D) = "white" {} _Strength("Gradient Strength", Range(0,1)) = 1 _TopColor("Top Color", Color) = (1,1,1,1) _BottomColor("Bottom Color", Color) = (0,0,0,0) _GradientEnd("Gradient End Position", Range(0,1)) = 1 _LightPosition("Light Position", Vector) = (0.5, 1.0, 0, 0) _NoiseScale1("Noise Scale 1", Float) = 12.0 _NoiseScale2("Noise Scale 2", Float) = 2.0 _AlphaCutoff("Alpha Cutoff", Range(0,1)) = 0.0 } SubShader { Tags { "RenderType"="Transparent" "Queue"="Transparent" } LOD 100 Pass { Blend SrcAlpha OneMinusSrcAlpha ZWrite Off CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; }; sampler2D _MainTex; float _Strength; float4 _TopColor; float4 _BottomColor; float _GradientEnd; float4 _LightPosition; float _NoiseScale1; float _NoiseScale2; float _AlphaCutoff; v2f vert(appdata v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.uv = v.uv; return o; } // Perlin noise implementation float fade(float t) { return t * t * t * (t * (t * 6 - 15) + 10); } float lerp(float a, float b, float t) { return a + t * (b - a); } float grad(int hash, float x, float y) { int h = hash & 7; float u = h < 4 ? x : y; float v = h < 4 ? y : x; return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v); } int perm(int x) { // Simple permutation function for shader use return (x * 34 + 1) * x % 289; } float noise(float2 uv) { float2 p = floor(uv); float2 f = frac(uv); int X = int(p.x); int Y = int(p.y); int A = perm(X) + Y; int B = perm(X + 1) + Y; float res = lerp( lerp(grad(perm(A), f.x, f.y), grad(perm(B), f.x - 1, f.y), fade(f.x)), lerp(grad(perm(A + 1), f.x, f.y - 1), grad(perm(B + 1), f.x - 1, f.y - 1), fade(f.x)), fade(f.y) ); return res * 0.5 + 0.5; // Normalize to [0,1] } fixed4 frag(v2f i) : SV_Target { // Remap uv.y so gradient ends at _GradientEnd // float t = saturate(i.uv.y / max(_GradientEnd, 0.0001)); // float2 center = float2(0.5, 1.0); float noiseValue = noise(i.uv*_NoiseScale1 + float2(_Time.x*1.3, _Time.y*0.2)); float2 uvNorm = (i.uv - _LightPosition.xy + 0.1*float2(noiseValue, noiseValue)); //uvNorm.x /= (_GradientEnd); // scale x to match circle aspect float dist = 1.0 - length(uvNorm); // dist=1.0-(pow(1.0 - dist, 2.0)); // Sharpen the edge float t = saturate((dist - (1.0 - _GradientEnd)) / _GradientEnd); // Apply ease (smoothstep) for non-linear gradient t = smoothstep(0.0, 1.0-_Strength*0.5, t); float n = noise(i.uv *_NoiseScale2 + _Time.yx * 0.8); t *= n; // Adjust 0.1 for edge softness t = saturate(t); t=1.0-pow(1.0 - t, 1.5); // Make the gradient more pronounced float4 gradColor = _BottomColor*(1.0-t)+_TopColor*t; // float4 texColor = tex2D(_MainTex, i.uv); // return lerp(float4(0.0, 0.0, 0.0, 0.0), gradColor, _Strength); gradColor.a*=_AlphaCutoff; return gradColor; // return gradColor; } ENDCG } } }