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

Scene depth doesn't work in HDRP?

Discussion in 'High Definition Render Pipeline' started by Roggi_, Oct 28, 2019.

  1. Roggi_

    Roggi_

    Joined:
    May 14, 2014
    Posts:
    84
    Hi, this is driving me crazy. If you make an empty pbr graph and just connect the scene depth note to alpha, set the render mode to transparent, the shader only works in LWRP. It's completly broken in HDRP. And it has been for several months. Is there really no way for me to use depth buffer in the shader graph?
     
  2. konsic

    konsic

    Joined:
    Oct 19, 2015
    Posts:
    995
    I need this too.
     
  3. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    880
    What is the version of HDRP? What is the version of unity?
    Scene depth works for me.
     
  4. Roggi_

    Roggi_

    Joined:
    May 14, 2014
    Posts:
    84
    I had the same issues on several machines, several versions of unity and hdrp over the course of several month, checking each time if it's fixed. Most recently, 2019.2.10 unity and 6.9.2 hdrp.
    What versions work for you?
     
  5. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    880
    Ok, turns out it works only for Unlit in HDRP 7.1.2 for me. Did you open the case?
     
  6. frances_farmer

    frances_farmer

    Joined:
    Aug 29, 2019
    Posts:
    11
    Broken for me also in the most recent version of HDRP. I will log a bug report when I get home later.
     
  7. texcoord3

    texcoord3

    Joined:
    Oct 12, 2019
    Posts:
    3
    also broken for me, still.
     
  8. SebLazyWizard

    SebLazyWizard

    Joined:
    Jun 15, 2018
    Posts:
    233
    Any chance that you guys use keywords in your shader graphs?
    If so, then that's the reason why.
    Keywords are still super buggy and break many shader features like scene depth/color, transmission and depth-offset (for parallax mapping).
     
  9. texcoord3

    texcoord3

    Joined:
    Oct 12, 2019
    Posts:
    3
    That's definitely possible - I ended up getting it to work but I don't know how unfortunately.
     
  10. Roggi_

    Roggi_

    Joined:
    May 14, 2014
    Posts:
    84
    No keywords used in the shader. I reported the issue and it was confirmed that it's broken.
     
  11. Lute-Li

    Lute-Li

    Joined:
    Apr 3, 2018
    Posts:
    1
    I always thought it was a problem with the HDRP settings. I searched on the Internet for a whole day and still couldn't find the answer. I didn't know until I saw this now that HDRP settings can't solve this problem.
     
  12. frances_farmer

    frances_farmer

    Joined:
    Aug 29, 2019
    Posts:
    11
    Do we know if this is fixed now that HDRP is released?
     
  13. Roggi_

    Roggi_

    Joined:
    May 14, 2014
    Posts:
    84
  14. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    257
    Hello,

    I just tried to repro and it seems that it's working as expected for me, here's what i did:
    - Create a new PBR shader graph
    - Switch the graph to transparent
    - Add a scene depth node in Eye space with a fraction and set the albedo to red like so:
    upload_2020-1-30_18-52-56.png
    - Then i created a material from this graph and assigned it to a quad in my scene:
    SceneDepth.gif

    As you can see, the alpha of the quad is affected with the depth of objects behind it.
     

    Attached Files:

    Leniaal and konsic like this.
  15. Roggi_

    Roggi_

    Joined:
    May 14, 2014
    Posts:
    84

    Ineed you are right, it's working in HDRP 7+. Not sure how I managed to not get it to work when i tested it 2 days ago.

    Would you happen to know how to use that depth to make an intersection highlight effect with other meshes?
     
  16. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    257
    Yeah sure, the main idea is to compare the view space position of your object with the depth of the scene in eye space, but there is a catch: the actual z component of the position in view space is negative so to compare it to the scene depth you just have to add both values like this:
    upload_2020-2-3_11-13-5.png
    And it will result in something like this:
    upload_2020-2-3_11-15-0.png
     
    valarnur, lilacsky824 and Roggi_ like this.
  17. Roggi_

    Roggi_

    Joined:
    May 14, 2014
    Posts:
    84
    Thanks so much!
     
    antoinel_unity likes this.
  18. frances_farmer

    frances_farmer

    Joined:
    Aug 29, 2019
    Posts:
    11
    Very cool, glad to see it is working now.
     
  19. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Does this work on HDRP 7.3.1? I couldn't get Antoinel's example to function. Is there something specific in addition to the graph that needs to be configured in a special way in Pipeline Asset or such?
     
  20. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    703
    Also double check that the material you are using is not overriding the surface type you've set in the master node.
     
    Olmi likes this.
  21. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    That did it. Thanks @Remy_Unity. Somehow I forgot to check that even though I should be aware of it...
     
  22. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    The Scene Depth node only works intermittenly for me. I have brand new shaders that i put it in and it works... make a few changes in shader graph and bam... stops working. I even connect the output of the scene depth directly to the albedo and nothing... no data. Create a new material.. works again.
     
  23. OneManEscapePlan

    OneManEscapePlan

    Joined:
    Oct 14, 2015
    Posts:
    218
    Do you need to wait for the shader to recompile? That's tripped me up a few times.
     
  24. transporter_gate_studios

    transporter_gate_studios

    Joined:
    Oct 17, 2016
    Posts:
    219
    i mean its shader graph. if it didnt compile i wouldnt see anything on the material.
     
  25. ShaneW

    ShaneW

    Joined:
    Feb 22, 2021
    Posts:
    2
    Scene Depth isnt working at all for unity 2021 for the URP (ive only tried URP), it returns nothing.. Ive tried on a brand new project, can confirm what transporter_gate_studios has said.

    Also shaders from the asset store that use it also do not work, it also seems enabling/disabling the depth texture toggle does nothing on the camera or the pipeline settings.

    Works perfectly in 2020.
     
  26. Darkgaze

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    381