Search Unity

Question Depth hidden in Unity 2021?

Discussion in 'Universal Render Pipeline' started by yonatanab1, Aug 3, 2022.

  1. yonatanab1

    yonatanab1

    Joined:
    Sep 9, 2018
    Posts:
    56
    I am following this tutorial, and at the timestamped linked: (t=81 or 1:22)


    They change the depth of the texture.

    I Can't find that option, even after enabling it on my shader settings asset.
    upload_2022-8-3_6-57-51.png
    (Depth Texture and Opaque Texture are checked)

    What should I do to activate it?
    I am using Unity 2021.3.0f1.
     
  2. alexpana_

    alexpana_

    Joined:
    Mar 5, 2017
    Posts:
    10
    That Depth property is a shader property that's added to the shader graph at 2:16. It's not a global setting, it's a material property for that specific shader.
     
  3. yonatanab1

    yonatanab1

    Joined:
    Sep 9, 2018
    Posts:
    56
    Thanks,
    I added it and changing it's values doesn't do anything...
    I connected the system there to the base color of a lit shader graph.

    also on the same tutorial, my Strength value only makes a difference between 0 and 0.0001.
    Something seems to be wrong, do you know what it could be? 1.png 2.png
     
  4. alexpana_

    alexpana_

    Joined:
    Mar 5, 2017
    Posts:
    10
    Can you check if your shader's surface is transparent and the material render queue is 3000? Depth information is only available for objects already rendered, and transparent objects are always rendered after opaque ones, making sure the water is rendered after the terrain.
     
  5. yonatanab1

    yonatanab1

    Joined:
    Sep 9, 2018
    Posts:
    56
    Surface type is set to transparent,
    Material render queue is [from shader] 3000.
    Screenshot 2022-08-05 105942.png

    depth still doesn't seem to do anything.

    I also tried downloading an online water shader from the asset store, and it works fine except from the depth of the texture. I also tried using post processing effects but it didn't change anything.

    what should I do?
     
  6. alexpana_

    alexpana_

    Joined:
    Mar 5, 2017
    Posts:
    10
    Let's see if unity renders the depth texture:

    1. Start the game in Game view
    2. Open the Window -> Analysis -> Frame Debugger tool
    3. Click "Enable" in the Frame Debug window
    4. Find your camera, and check two things:
    4.1 The "DrawTransparentObjects" scope contains at least a draw call with your water shader that receives the shader property "_CameraDepthTexture"

    upload_2022-8-6_9-19-49.png

    4.2 There is a "CopyDepth" pass for your camera which renders the camera depth attachment to the previously inspected "_CameraDepthTexture"
    upload_2022-8-6_9-21-19.png
    If the screen is pitch black when you select "CopyDepth", try reducing the upper limit of the "Levels" range slider in the upper right toolbar of the details panel in Frame Debug.

    This should tell you if you have a proper depth texture available to your shader.
     
  7. yonatanab1

    yonatanab1

    Joined:
    Sep 9, 2018
    Posts:
    56
    upload_2022-8-6_13-15-37.png
    Checked, it is black and Playing with the Levels Slider doesn't change anything.
    does this mean that depth isn't working in my Unity engine, or did I use the depth node wrong?

    Thanks for helping me by the way!
     
  8. alexpana_

    alexpana_

    Joined:
    Mar 5, 2017
    Posts:
    10
    It looks like your scene is empty or all objects are disabled, you should have a "DrawOpaqueObjects" pass before the "CopyDepth" pass. In your screenshot, the depth buffer is copied immediately after being cleaned, and nothing is rendered before. There are no opaque objects being drawn in your scene at all, meaning nothing contributes to the depth buffer.
     
  9. yonatanab1

    yonatanab1

    Joined:
    Sep 9, 2018
    Posts:
    56
    upload_2022-8-6_22-4-56.png
    Sorry about that,

    I added terrain and a few cubes underwater. here is what I get after selecting CopyDepth. (and reducing the Levels slider)