Shader "Unlit/DepthShader"
{
    Properties
    {
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM

            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
            };

            struct v2f
            {
				float depth : TEXCOORD0;
                float4 vertex : SV_POSITION;
				float3 worldPos: TEXCOORD1;
            };

			//uniform float4 _ProjectionParams;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
				o.depth = COMPUTE_DEPTH_01;
				o.worldPos = mul(unity_ObjectToWorld, v.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
				return fixed4(length(i.worldPos - _WorldSpaceCameraPos.xyz) * _ProjectionParams.w, 0, 0, 1);
            }
            ENDCG
        }
    }
}
