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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

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:
    123
    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:
    105
  3. psuong

    psuong

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

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    237
    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:
    123
    Okay - I'll give this a try, thanks!