Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Injecting and executing a CustomPass in HDRP.

Discussion in 'High Definition Render Pipeline' started by psuong, Feb 9, 2023.

  1. psuong

    psuong

    Joined:
    Jun 11, 2014
    Posts:
    126
    So I'm following the package doc's guide on CustomPasses and I'm wondering how can I inject my custom pass into the actual RenderPass for HDRP.

    Everytime the CustomPass is injected via the CustomPassVolume it ends up being the very first render pass that's executed. See the screenshot below.

    upload_2023-2-9_15-11-39.png

    Here is a screenshot of the CustomPassVolume and the injection point is After Post Process.
    upload_2023-2-9_15-12-28.png

    Unfortunately, I'm pretty much only familiar with Builtin and URP so the workflow is pretty different than what I'm used to.

    The ImGuiHDRPRenderPass is pretty simple because all I need it to do is execute a command buffer. Here is a link to the gist: https://gist.github.com/psuong/72c3c4afe3bb6ac5b18d52b91b44f2f7

    There is some setup done to the Command Buffer initially and the general idea is that

    1. Setup the ViewProjectionMatrix to be orthographic (effectively full screen)
    2. Setup the draw command to draw a mesh
    3. The ImGuiHDRPRenderPass executes the command buffer at the injection point.

    While this works well with URP and Builtin - I'm struggling to get this working nicely in HDRP 14.0.5 and Unity 2022.2.4
     
  2. Matjio

    Matjio

    Unity Technologies

    Joined:
    Dec 1, 2014
    Posts:
    110
  3. psuong

    psuong

    Joined:
    Jun 11, 2014
    Posts:
    126
    Matjio likes this.
  4. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    271
    Hello,

    In your code, I can see that you're caching the first command buffer received in the Setup() function. in HDRP it's not guaranteed that you'll have the same command buffer for each frame, that's why it's best to use the command buffer in CustomPassContext (in the Execute function).

    Also since HDRP also uses the command buffer execution, the custom pass evaluation happens before the graphics commands are pushed to the GPU. This means that when you do renderContext.ExecuteCommandBuffer (which is instant) your command buffer actually ends up before the HDRP one. To make sure your commands are included at the correct place in HDRP you have two choices:
    - Append all your commands to the command buffer in the CustomPassContext.
    - call the ExecuteCommandBuffer on the HDRP command buffer to flush commands on the device.

    I can also see that you're caching the ScriptableRenderContext, I'm not sure what are the implications of this but I'd say it's safer to use the one in CustomPassContext
     
    psuong and m0nsky like this.
  5. psuong

    psuong

    Joined:
    Jun 11, 2014
    Posts:
    126
    Okay - I'll give this a try, thanks!