Hi
I have a bit of an issue with the RenderPipelineManager.endCameraRendering callback.
What I am trying to do is to render a few additional meshes inside this callback. This works without any issues in the universal pipeline.
Note: these meshes are unlit and intended as an overlay. They do not have to interact with the HDRP’s post processing stack at all.
However in HDRP the pipeline has a command buffer that it builds up as the pipeline is executed and only at the end does it call renderContext.ExecuteCommandBuffer. The issue is then that even though the endCameraRendering callback is called at the right time it is impossible to inject any custom rendering because the HDRP’s command buffer will override everything later anyway.
Currently the HDRP’s rendering code looks like
cmd.SetInvertCulling(renderRequest.cameraSettings.invertFaceCulling);
UnityEngine.Rendering.RenderPipeline.BeginCameraRendering(renderContext, renderRequest.hdCamera.camera);
ExecuteRenderRequest(renderRequest, renderContext, cmd, AOVRequestData.@default);
cmd.SetInvertCulling(false);
UnityEngine.Rendering.RenderPipeline.EndCameraRendering(renderContext, renderRequest.hdCamera.camera);
I would propose that this is changed to
cmd.SetInvertCulling(renderRequest.cameraSettings.invertFaceCulling);
UnityEngine.Rendering.RenderPipeline.BeginCameraRendering(renderContext, renderRequest.hdCamera.camera);
ExecuteRenderRequest(renderRequest, renderContext, cmd, AOVRequestData.@default);
cmd.SetInvertCulling(false);
// Added code
// Execute the current command buffer and get a new one.
// This ensures that any command buffer execution inside EndCameraRendering will happen at the correct time
renderContext.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
cmd = CommandBufferPool.Get();
// End added code
UnityEngine.Rendering.RenderPipeline.EndCameraRendering(renderContext, renderRequest.hdCamera.camera);
Or is there any other way of rendering inside the endCameraRendering callback which actually works with the HDRP?
[EDIT] Interestingly there is one case where it actually does work as expected. This is if the camera is rendered with gizmos enabled. Why? Because the HDRP’s RenderGizmos function does
renderContext.ExecuteCommandBuffer(cmd);
cmd.Clear();
renderContext.DrawGizmos(camera, gizmoSubset);
and since it is the last thing that is rendered by the camera everything will be setup sort of as we want it in the endCameraRendering callback. It would be nice if this could be done in a well supported way though.