Shader "Hidden/PlayerFade"
{
    Properties
	{
		_Radius("Viewing Radius", Float) = 0.3
		_Falloff("Falloff Percent", Float) = 0.8
		_Color("Fade Color", Color) = (0,0,0,1)
		_MainTex("Texture", 2D) = "white" {}
		_MainCameraPos("Rendering Camera Screen Pos", Vector) = (0,0,0,0)
    }
    SubShader
    {
        // No culling or depth
        Cull Off ZWrite Off ZTest Always

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

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

            struct v2f
            {
                float4 vertex : SV_POSITION;
				float2 uv : TEXCOORD0;
            };

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

			sampler2D _MainTex;

			uniform float2 _MainCameraPos;
			uniform float _Radius;
			uniform float _Falloff;

			uniform float4 _Color;

            fixed4 frag (v2f i) : SV_Target
            {
				float2 dist = i.uv - _MainCameraPos;
				dist.y *= _ScreenParams.y / _ScreenParams.x;

				float3 clearDist = _Radius * _Falloff;

				//float fade = step(clearDist, length(dist));
				float fade = smoothstep(clearDist, _Radius, length(dist));

				fixed4 col = tex2D(_MainTex, i.uv);

				//return fixed4(screenPos.xy / _ScreenParams.xy, 0, 1);

				//return fixed4(i.screenPos.xy, 0, 1);

				return col * (1 - fade) + _Color * fade;
            }
            ENDCG
        }
    }
}
