Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

RenderPipelineManager.endCameraRendering cannot be used for custom rendering in HDRP

Discussion in 'High Definition Render Pipeline' started by half_voxel, Nov 21, 2019.

  1. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    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

    Code (CSharp):
    1. cmd.SetInvertCulling(renderRequest.cameraSettings.invertFaceCulling);
    2. UnityEngine.Rendering.RenderPipeline.BeginCameraRendering(renderContext, renderRequest.hdCamera.camera);
    3. ExecuteRenderRequest(renderRequest, renderContext, cmd, AOVRequestData.@default);
    4. cmd.SetInvertCulling(false);
    5. UnityEngine.Rendering.RenderPipeline.EndCameraRendering(renderContext, renderRequest.hdCamera.camera);
    I would propose that this is changed to

    Code (CSharp):
    1. cmd.SetInvertCulling(renderRequest.cameraSettings.invertFaceCulling);
    2. UnityEngine.Rendering.RenderPipeline.BeginCameraRendering(renderContext, renderRequest.hdCamera.camera);
    3. ExecuteRenderRequest(renderRequest, renderContext, cmd, AOVRequestData.@default);
    4. cmd.SetInvertCulling(false);
    5. // Added code
    6. // Execute the current command buffer and get a new one.
    7. // This ensures that any command buffer execution inside EndCameraRendering will happen at the correct time
    8. renderContext.ExecuteCommandBuffer(cmd);
    9. CommandBufferPool.Release(cmd);
    10. cmd = CommandBufferPool.Get();
    11. // End added code
    12. 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
    Code (CSharp):
    1. renderContext.ExecuteCommandBuffer(cmd);
    2. cmd.Clear();
    3. 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.
     
    Last edited: Nov 21, 2019
  2. Julien_Unity

    Julien_Unity

    Unity Technologies

    Joined:
    Nov 17, 2015
    Posts:
    72
    Good catch. This should be fixed in 7.1.6.
     
  3. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Awesome! Thank you!