Shader "Custom/DepthOnly" { SubShader { Tags { "RenderType"="Opaque" } Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct v2f { float4 pos : SV_POSITION; float depth : TEXCOORD0; }; v2f vert(appdata_base v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.depth = o.pos.z / o.pos.w; return o; } fixed4 frag(v2f i) : SV_Target { // Output depth as grayscale return fixed4((i.depth / 2), (i.depth / 2), (i.depth / 2), 1.0); } ENDCG } } FallBack "Diffuse" }