Injecting and executing a CustomPass in HDRP.

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.

Here is a screenshot of the CustomPassVolume and the injection point is After Post Process.
8794249--1195174--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: ImGuiHDRPRenderPass.cs · GitHub

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

Hi!
Not sure why it is there but maybe you can check this repo with some examples of custom passes:
https://github.com/alelievr/HDRP-Custom-Passes
For UI you might as well consider this one as a reference:
https://github.com/alelievr/HDRP-UI-Camera-Stacking
-Mat

Okay - let me take a look at HDRP - Custom Passes and see what I can gather. I might just be doing something wrong.

1 Like

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

2 Likes

Okay - I’ll give this a try, thanks!