- Home /
 
               Question by 
               magicaxis · Dec 05, 2014 at 05:53 AM · 
                shaderrenderscreenshotdepth  
              
 
              Increasing the level of detail with a depth render
I'm making a psychology experiment which takes a few renders of what the camera sees, including a depth render. It looks like this: 
The program is finished, except that my client wants the ramp of black-to-white colours to be more precise, have a higher resolution...More shades of grey.
The shader I am using is this one:
 //Shows the grayscale of the depth from the camera.
  
 Shader "Custom/DepthShader"
 {
     SubShader
     {
         Tags { "RenderType"="Opaque" }
  
         Pass
         {
  
             CGPROGRAM
             #pragma target 3.0
             #pragma vertex vert
             #pragma fragment frag
             #include "UnityCG.cginc"
  
             uniform sampler2D _CameraDepthTexture; //the depth texture
  
             struct v2f
             {
                 float4 pos : SV_POSITION;
                 float4 projPos : TEXCOORD1; //Screen position of pos
             };
  
             v2f vert(appdata_base v)
             {
                 v2f o;
                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                 o.projPos = ComputeScreenPos(o.pos);
  
                 return o;
             }
  
             half4 frag(v2f i) : COLOR
             {
                 //Grab the depth value from the depth texture
                 //Linear01Depth restricts this value to [0, 1]
                 float depth = Linear01Depth (tex2Dproj(_CameraDepthTexture,
                                                              UNITY_PROJ_COORD(i.projPos)).r);
  
                 half4 c;
                 c.r = depth;
                 c.g = depth;
                 c.b = depth;
                 c.a = 1;
  
                 return c;
             }
  
             ENDCG
         }
     }
     FallBack "VertexLit"
 }
Which I got from the internet somewhere.
I am taking the screenshots with this code:
 void TakeScreenShot(Camera customCamera, int resWidth, int resHeight, string rendertype, int favNum)
     {
         RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
         customCamera.targetTexture = rt;
         Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.ARGB32, false);
         customCamera.Render();
         RenderTexture.active = rt;
         screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
         customCamera.targetTexture = null;
         RenderTexture.active = null; // JC: added to avoid errors
         Destroy(rt);
         byte[] bytes = screenShot.EncodeToPNG();
         string filename = ScreenShotName(rendertype, favNum);
         System.IO.File.WriteAllBytes(filename, bytes);
         Debug.Log(string.Format("Took screenshot to: {0}", filename));
     }
 
Is there any way to improve the contrast, the level of colour difference detail in these renders?
 
                 
                3.png 
                (517.7 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                