Search Unity

No depth information in "After Depth and Normal" custom pass injection point

Discussion in 'High Definition Render Pipeline' started by Laex410, Mar 2, 2020.

  1. Laex410

    Laex410

    Joined:
    Mar 18, 2015
    Posts:
    51
    Hey everyone,

    I started working with the custom pass feature in HDRP and ran into a slight issue. I am trying to draw occluded opaque geometry with a specific color (pretty basic effect in lots of games), so I set up a custom pass that does exactly that and chose the "After Depth and Normal" injection point.

    upload_2020-3-2_12-46-6.png

    It appears as if there's no depth information available at this point though (ZTest Greater doesn't work) which is kind of strange, isn't the whole idea of this point to have the depth information available?

    As a workaround I can choose the "Before Transparent" injection point where the depth information appears to be present, but I would have to render the object as a transparent object to make sure it gets rendered after the occlusion highlight to fix having a highlight due to self occlusion (which is obviously not ideal).

    upload_2020-3-2_12-50-20.png

    Am I missing something here or is it a bug?
    Do I have to manually write to DEPTH in the enviromental shaders?
    Do I have to sample the depth texture instead of relying on ZTest?

    Thanks for the help, I really appreciate it!

    - Alex
     
  2. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    265
    Hey,

    I tested locally and it appears to be working like intended: Occlusion.gif
    Just don't forget to write to the depth buffer when doing this kind of effect because otherwise the geometry that will be renderer afterwards will overwrite it (this geom is not rendered using ZTest LEqual but with Equal because they are supposed to be rendered in the depth-prepass and when you write your own depth here it makes the ZTest Equal fail for these objects)
     
  3. Laex410

    Laex410

    Joined:
    Mar 18, 2015
    Posts:
    51
    Thanks for the quick reply! I tried replicating your setup and while it's basically working I still have the issue that I get highlights on the object due to it's own occlusion. What would be the best solution to handle this issue in HDRP?

    upload_2020-3-2_14-51-8.png

    I think you might have to same issue in your demo but can't see it due to backface culling and the object thus not having multiple surfaces on top of each other.
     
  4. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    It's not easy to understand what's happening here, if it's an issue with the custom pass feature or the setup that you made.
    Would it be possible for you to share the project, maybe by PM ?
     
  5. Laex410

    Laex410

    Joined:
    Mar 18, 2015
    Posts:
    51
    I prepared a clean new HDRP project with the same setup for you so you can take a look. In addition to the self occlusion I am also getting this weird tiling issue which looks as if the depth texture resolution is much lower than the viewport resolution, not sure what's going on there.

    upload_2020-3-2_15-49-36.png

    Using Unity 2019.3.2f1, HDRP version 7.18

    You can download the project here: https://drive.google.com/open?id=1nZW90HXUL0HysZuZ1DWNFIes0Ql6mVMK

    If you need additional information let me know!
     
  6. Laex410

    Laex410

    Joined:
    Mar 18, 2015
    Posts:
    51
    I might be wrong here but isn't it just an issue with the way HDRP is designed instead of a bug or setup issue?

    Isn't the custom pass at the "After Depth and Normal" stage expected to also highlight areas that are hidden behind the object itself (like e.g. the right ear behind the left ear)?

    The depth for the scene at the "After Depth and Normal" stage should look something like this:

    upload_2020-3-2_16-43-11.png

    Therefore faces of the object that are occluded by the object itself and face the camera are highlighted in the custom pass.

    In order to fix this I'd need to render the depth of the whole scene, then render the highlight, and afterwards render the depth of the highlighted object and continue rendering as usual. Is there a way to set something like this up in HDRP other than rendering the highlighted object as transparent?
     
  7. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    We made it work, see the modified project : https://drive.google.com/open?id=17rMQl5iQjUqJfb3aaUQdyNMdte0teBhB

    Idea is :
    • Use "Before Pre-Refraction" injection point
    • Change the object base material to "Transparent", so the proper keywords are set
    • First draw the unlit object with z-test Greater (note that I just realized I forgot to disable double side rendering)
    • Then draw the regular object with z-test L-Equal using the "Forward" pass of the material
    upload_2020-3-2_19-32-21.png
     
  8. Laex410

    Laex410

    Joined:
    Mar 18, 2015
    Posts:
    51
    Thank you very much for your help! I was hoping to avoid rendering the model with a transparent material due to Overdraw, but I think this might not be possible in the current HDRP.

    upload_2020-3-2_23-2-56.png

    Going forward I might have to look into writing a custom pipeline to have more control over the setup