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; float4 pos2 : TEXCOORD2; }; v2f vert(appdata_base v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); // o.depth = (o.pos.z + 1.) / 2. / o.pos.w; // o.depth = (o.pos.z + 1.) / 2.; o.depth = o.pos.z; // o.depth = o.pos.z/ o.pos.w ; //o.depth = mul(UNITY_MATRIX_M, v.vertex).x; // o.pos2 = o.pos; return o; } fixed4 frag(v2f i) : SV_Target { // ****We had to change Unity's color space to Gamma such that it doesn't add its own gamma correction, // for this to work ******* return fixed4(i.depth, i.depth, i.depth, 1.0); // Output depth as grayscale // return fixed4((i.depth), (i.depth), (i.depth), 1.0); // return fixed4( // (i.pos2.x) * .5 + .5, // (i.pos2.x) * .5 + .5, // (i.pos2.x) * .5 + .5, 1.0); } ENDCG } } FallBack "Diffuse" }