Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Official Compute Thickness pass Feedbacks / Support

Discussion in 'High Definition Render Pipeline' started by chap-unity, Jan 25, 2023.

  1. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    562
    Hi !
    In 2023.1, part of the focus on HDRP was the improvement of transparents in general.

    Among other tasks, HDRP now provides a fullscreen pass to compute the accumulated thickness for objects on a given **LayerMask**.

    HDRP computes optical path and the overlap count (i.e the number of triangles traversed), which can be useful for instance for SubSurface Scattering or Refraction.

    The overlap count can be used for flat or non-closed objects like vegetation.

    There’s a few limitations when mixing Transparent and Opaque objects but it should work with any type of material.

    This post is to centralize feedback and support for this specific features and transparency questions in general.

    Documentation is coming but in the meantime, here’s a few tips to use this if someone is interested:
    • Compute Thickness needs to be enabled on the Default Frame Settings under Rendering foldout
    • Compute Thickness needs to be enabled on the current HDRP Asset
    • One or more layer needs to be checked under the Compute Thickness properties in the HDRP asset
    • One or more object has to be in the one of those selected layer for the pass to be filled with any meaningful data
    • Lastly, the result of the thickness pass is accessible via the HD Sample Buffer node in the Shader graph. The node requires the layer index as input

    Default Frame Settings



    HDRP Asset



    Layer index



    HD Sample Buffer node



    The use cases:
    • More accurate Refraction and Absorption without having to author a thickness map.




    • SubSurfaceScattering/Translucency with no thickness map needed


    • For Vegetation and non closed objects, an overlap count can be used to multiply the thickness of leaves to have a fake accumulation for dense alpha clipped vegetation for exemple.


    Varying the thickness of the leaves (see attached gif)
    • This can be used as well in more creative ways like sampling the thickness of objects in other layers than the one the object is to create X-Rays effects like.


    This will be demonstrated further in an upcoming sample on transparency as well.

    Limitations :
    • Does not support Tessellation
    • Mixing open and closed mesh on the same layer can cause negative values. For better results, use separate layers.
    • Mixing transparent and opaque objects can creates unexpected results due to when the transparent object are rendered in HDRP
    Cheers!
     

    Attached Files:

    Last edited: Jan 25, 2023
  2. Kleptine

    Kleptine

    Joined:
    Dec 23, 2013
    Posts:
    211
    Can you talk any more about the underlying technique? What's the performance cost?
     
  3. SoufianeKHIAT

    SoufianeKHIAT

    Unity Technologies

    Joined:
    Jan 16, 2020
    Posts:
    7
    It add a simple fullscreen pass to compute the thickness of multiple object at the same time for each given layer. That sample the existing depth buffer to have the thickness interacting with the environement cf. the image of the green glass dragon interacting with the plane.

    You have a control on the performance by controlling the resolution of this layer it can be full screen, half resolution or quarter resolution.
    upload_2023-1-27_11-31-45.png
     
  4. darkfrontiers

    darkfrontiers

    Joined:
    Apr 4, 2022
    Posts:
    13
    Do standard lit shaders support this feature or only custom shader graphs? It doesn't seem to work with standard materials no matter what I try. Also do materials in those layers that don't have transparency option enabled still render to thickness buffer? That would be excessive, because I want to use layers for other game features too.
     
  5. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    562
    For the buffer to be filled with the thickness of the object, the object needs to be in a layer and that layer needs to be selected in the HDRP asset list.
    Then the only way to sample this buffer is via shader graph by using HDSampleBuffer node.
    So, you don't have to use shader graph for object to write their thickness into the buffer, but you have to use shader graph to read that texture and do something with it.

    And yes, it's compatible with transparent and opaque objects.

    The best way to setup this would be to have a specific layer for object that needs to write their thicknesses and only use that layer for that and nothing else.
     
  6. darkfrontiers

    darkfrontiers

    Joined:
    Apr 4, 2022
    Posts:
    13
    I mostly use layers for collision matrices, camera culling and other things (creating multiple layers for same purpose but with thickness is not an option). Wouldn't it be a better way to have shader pass do the rendering into buffer, rather than layer? This would automatically select materials that have thickness boolean enabled similary to how receive SSR, decals works. Or this would suck up the performance?
     
  7. SoufianeKHIAT

    SoufianeKHIAT

    Unity Technologies

    Joined:
    Jan 16, 2020
    Posts:
    7
    That would be possible, but that will block us to split object on different layer. For instance we can split transparent and opaque on different thickness layers to avoid interaction issues.
    We'll think about it as an improvement to have an index reserved for material-based selection if possible.
     
  8. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    567
    Had a brief test run of the feature, works very well out of the box! It was easy to setup in shader graph, and I did not encounter any issues. Seems to even work properly in XR, unlike nearly all other features I tested which were introduced in the 2022 / 2023 cycle.
    It allows much more dynamic thickness calculation which would not be possible with thickness maps.
    Two thumbs up:)
    Edit: And the performance seems really good, minimal impact on GPU time.
     
    chap-unity likes this.