- Home /
 
               Question by 
               FreakyDevA · May 17, 2018 at 11:05 AM · 
                shaderrenderingdepthdepth-bufferreplacement shader  
              
 
              Is it possible to create a depth render of scene using a replacement shader?
I want to create a shader that is set as a replacement shader to the camera and renders the scene's depth much like what is seen in this image.
I tried the depth shader below but it my results seem to be wrong as seen in this image
 Shader "Hidden/DepthShader"
 {
     Properties
     {
         _MainTex("Base (RGB)", 2D) = "white" {}
     }
     SubShader
     {
     Pass
     {
         CGPROGRAM
 
         #pragma vertex vert
         #pragma fragment frag
         #include "UnityCG.cginc"
 
         uniform sampler2D _MainTex;
         uniform sampler2D _CameraDepthTexture;
         uniform half4 _MainTex_TexelSize;
 
         struct input
         {
             float4 pos : POSITION;
             half2 uv : TEXCOORD0;
         };
 
         struct output
         {
             float4 pos : SV_POSITION;
             half2 uv : TEXCOORD0;
         };
 
 
     output vert(input i)
     {
         output o;
         o.pos = UnityObjectToClipPos(i.pos);
         o.uv = MultiplyUV(UNITY_MATRIX_TEXTURE0, i.uv);
         #if UNITY_UV_STARTS_AT_TOP
         if (_MainTex_TexelSize.y < 0)
             o.uv.y = 1 - o.uv.y;
         #endif
 
         return o;
     }
 
     fixed4 frag(output o) : COLOR
     {
         float depth = UNITY_SAMPLE_DEPTH(tex2D(_CameraDepthTexture, o.uv));
         depth = pow(Linear01Depth(depth), 0.25);
         return depth;
     }
 
         ENDCG
     }
     }
 }
Any ideas as to what is going wrong here?
 
                 
                example.png 
                (219.8 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Depth Rendering Issue 0 Answers
Read depth buffer on the cpu 1 Answer
Complex Depth Shader 0 Answers
Using a camera replacement shader but keeping the underlying (original) colors? -4 Answers
How to get depth texture and render texture from one camera 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                