Shader "Custom/ParticleWave"
{
    Properties
    {
        _Color("Color", Color) = (1,1,1,1)
        _Radius("Radius", Range(0,1)) = 0.2
        _Thickness("Thickness", Range(0.001,0.5)) = 0.05
        _Frequency("Frequency", Range(1,100)) = 20
        _Amplitude("Amplitude", Range(0,1)) = 1
        _Softness("Softness", Range(0.0001,0.2)) = 0.02
    }

    SubShader
    {
        Tags
        {
            "Queue"="Transparent"
            "RenderType"="Transparent"
            "IgnoreProjector"="True"
        }

        Blend SrcAlpha OneMinusSrcAlpha
        Cull Off
        Lighting Off
        ZWrite Off

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
                fixed4 color : COLOR;
            };

            struct v2f
            {
                float4 pos : SV_POSITION;
                float2 uv : TEXCOORD0;
                fixed4 color : COLOR;
            };

            fixed4 _Color;
            float _Radius;
            float _Thickness;
            float _Frequency;
            float _Amplitude;
            float _Softness;

            v2f vert(appdata v)
            {
                v2f o;
                o.pos = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                o.color = v.color;
                return o;
            }

            fixed4 frag(v2f i) : SV_Target
            {
                // UV centered on billboard
                float2 p = i.uv * 2 - 1;

                // Radius from center
                float d = length(p);

                // Distance from moving wave
                float x = d - _Radius;

                // Envelope keeps only a narrow band
                float envelope = smoothstep(_Thickness + _Softness,
                                            _Thickness,
                                            abs(x));

                // Oscillating wave
                float wave = sin(x * _Frequency * 6.28318);

                // Convert [-1,1] to [0,1]
                wave = wave * 0.5 + 0.5;

                float alpha = envelope * wave * _Amplitude;

                return fixed4(_Color.rgb * i.color.rgb,
                              alpha * _Color.a * i.color.a);
            }
            ENDCG
        }
    }
}
