If you need the actual real world distance from a point in the scene to the camera, then you’ll need to reconstruct it’s position using camera matrices;
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 viewDir : TEXCOORD1;
}
v2f vert (appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos (v.vertex);
o.uv = v.uv;
//Find the view-space direction of the far clip plane from the camera (which, when interpolated, gives us per pixel view dir of the scene position)
o.viewDir = mul (unity_CameraInvProjection, float4 (o.uv * 2.0 - 1.0, 1.0, 1.0));
return o;
}
half4 frag (v2f i) : SV_Target
{
float depth01 = Linear01Depth (tex2D (_CameraDepthTexture, i.uv).r);
//Find the view-space position of the current pixel by multiplying viewDir by depth
float3 viewPos = (i.viewDir.xyz / i.viewDir.w) * depth01;
//Length of viewPos is the raw distance to the camera
return length (viewPos);
}