Search Unity

Question _CameraDepthNormalsTexture depth and normals don't return expected results

Discussion in 'Shaders' started by leosemm, Dec 12, 2022.

  1. leosemm

    leosemm

    Joined:
    May 5, 2022
    Posts:
    1
    I'm trying to generate a normals pass from the camera in the Built-In Render Pipeline, but when I use _CameraDepthNormalsTexture it only returns 1 in the normal blue channel and 0 for the other channels. The Depth just returns white. If I use _CameraDepthTexture the depth works fine.

    This is the code of the script on my camera
    Code (CSharp):
    1. public class ScreenDepthNormal : MonoBehaviour
    2. {
    3.     public Camera cam;
    4.     public Material mat;
    5.  
    6.     void Start()
    7.     {
    8.         Camera.main.depthTextureMode = DepthTextureMode.Depth | DepthTextureMode.DepthNormals;
    9.  
    10.         if(mat == null)
    11.         {
    12.             mat = new Material(Shader.Find("Hidden/Shader_ScreenDepthNormal"));
    13.         }
    14.     }
    15.  
    16.     void OnRenderImage(RenderTexture source, RenderTexture destination)
    17.     {
    18.         source.filterMode = FilterMode.Point;
    19.         //Graphics.Blit(source, destination);
    20.  
    21.         Graphics.Blit(source, destination, mat);
    22.     }
    23. }
    Here I call DecodeDepthNormal in the shader
    Code (CSharp):
    1. float4 Depth = tex2D(_CameraDepthTexture, i.uv);
    2.                 DecodeDepthNormal(tex2D(_CameraDepthTexture, i.uv), Depth.w, Depth.xyz);
    3.  
    4.                 float3 normalValues;
    5.                 float depthValue;
    6.  
    7.                 DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture, i.uv), depthValue, normalValues);
    If I return Depth it works just fine but when using DepthNormals it doesn't work as expected

    This is the Depth output
    upload_2022-12-12_21-53-32.png

    And this the normal output from _CameraDepthNormalsTexture:
    upload_2022-12-12_21-56-18.png

    Here you can see the Depth values from CameraDepthNormalsTexture
    upload_2022-12-12_21-58-6.png
     
  2. Cupret

    Cupret

    Joined:
    Nov 3, 2018
    Posts:
    1
    Bump! I stumble upon the same problem. Does anyone have any solution?