Shader "Hidden/NimbleFox/DepthToGrayscale" { SubShader { Cull Off ZWrite Off ZTest Always Pass { CGPROGRAM #pragma vertex vert_img #pragma fragment frag #include "UnityCG.cginc" UNITY_DECLARE_DEPTH_TEXTURE(_MainTex); float _DepthRangeNear; float _DepthRangeFar; fixed4 frag(v2f_img i) : SV_Target { float rawDepth = SAMPLE_DEPTH_TEXTURE(_MainTex, i.uv); float linearDepth = LinearEyeDepth(rawDepth); float normalizedDepth = saturate((linearDepth - _DepthRangeNear) / max(0.0001, _DepthRangeFar - _DepthRangeNear)); float grayscale = 1.0 - normalizedDepth; return fixed4(grayscale, grayscale, grayscale, 1.0); } ENDCG } } Fallback Off }