Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Depth Texture is black although everything is activated (URP)

Discussion in 'General Graphics' started by TheGeorg, Jul 2, 2022.

  1. TheGeorg

    TheGeorg

    Joined:
    Feb 21, 2018
    Posts:
    2
    Already struggling multiple days on this and finally decided to ask around.
    My unity project is based on a 2D Renderer asset and yes I did in fact activate it on the camera, pipeline asset and also on the 2d renderering data thingy.

    My material shader also has ZWrite On and is directly writing to the depth texture with:

    Code (CSharp):
    1.  
    2. half4 CombinedShapeLightFragment(v2f i, out float depth : SV_Depth) : SV_Target
    3. {
    4.        depth = 1.0;
    5.  
    6.        fixed4 c = tex2D(_MainTex, i.texcoord) * i.color;
    7.        c.rgb *= c.a;
    8.        return c;
    9. }
    10.  
    This also doesnt work. Still a black texture (It isnt all the way black, it has a hex value of 040404).

    I also looked over the frame debugger and it sais that the depth texture is only 16x16 big.
    Btw Im accessing the depth texture with Linear01Depth otherwise its gray.

    Thanks in advance. Im really struggling...
     
  2. TheGeorg

    TheGeorg

    Joined:
    Feb 21, 2018
    Posts:
    2
    Finally I found a solution. I bet its the worst solution ever but here goes nothing. I copied the URP scripts from the PackageCache to my Package folder and then changed the script Renderer2D so that it sets _CameraDepthAttachement to a global texture. Like this:

    Shader.SetGlobalTexture("_CameraDepthAttachment", m_DepthTextureHandle);


    Hope this helps somebody in the future...