Here's a simple version which should work both as a fullscreen post effect or as an object in the world, like a magic lens you can look through.

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
sampler2D _MainTex;
// Request camera depth buffer as a texture.
// Incurs extra cost in forward rendering, "just there" in deferred.
sampler2D _CameraDepthTexture;
void vert (
float4 vertex : POSITION,
out float4 outpos : SV_POSITION)
{
outpos = UnityObjectToClipPos(v.vertex);
}
fixed4 frag (UNITY_VPOS_TYPE screenPos : VPOS) : SV_Target
{
// Convert pixel coordinates into screen UVs.
float2 uv = screenPos.xy * (_ScreenParams.zw - 1.0f);
// Depending on setup/platform, you may need to invert uv.y
// Sample depth buffer, linearized into the 0...1 range.
float depth = Linear01Depth(
UNITY_SAMPLE_DEPTH(tex2D(_CameraDepthTexture, uv)));
// Compressing the range, so we get more colour
// variation close to the camera.
depth = saturate(2.0f * depth);
depth = 1.0f - depth;
depth *= depth;
depth = 1.0f - depth;
// Use depth value as a lookup into a colour
// ramp texture of your choosing.
fixed4 colour = tex2D(_MainTex, depth);
return colour;
}
ENDCG
}
Here I'm using the VPOS semantic to simplify calculating the position of the fragment on the screen. If you need to support shader models below 3 there are other ways to do this, they're just a little messier. ;)