Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

HDRP how to add command buffer to camera?

Discussion in 'Graphics Experimental Previews' started by Chaiker, Oct 14, 2018.

  1. Chaiker

    Chaiker

    Joined:
    Apr 14, 2014
    Posts:
    63
    Hello there. How I can add command buffers to camera in HDRP?
     
  2. ZAXIS

    ZAXIS

    Joined:
    Sep 30, 2016
    Posts:
    23
    Have you figured it out? I'm struggling with the same.
     
  3. jwheeler_unity

    jwheeler_unity

    Unity Technologies

    Joined:
    Nov 2, 2018
    Posts:
    7
    Something like this:

    Code (CSharp):
    1.        
    2.         void OnEnable()
    3.         {
    4.             var data = GetComponent<HDAdditionalCameraData>();
    5.             if (data != null) data.customRender += CustomRender;
    6.         }
    7.  
    8.         void OnDisable()
    9.         {
    10.             var data = GetComponent<HDAdditionalCameraData>();
    11.             if (data != null) data.customRender -= CustomRender;
    12.         }
    13.  
    14.         void CustomRender(ScriptableRenderContext context, HDCamera camera)
    15.         {
    16.             if (camera == null || camera.camera == null) return;
    17.  
    18.             // Target ID
    19.             var rt = camera.camera.targetTexture;
    20.             var rtid = rt != null ?
    21.                 new RenderTargetIdentifier(rt) :
    22.                 new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget);
    23.  
    24.             // Command
    25.             var cmd = CommandBufferPool.Get("your label");
    26.             CoreUtils.DrawFullScreen(cmd, _someMaterial, rtid);
    27.             context.ExecuteCommandBuffer(cmd);
    28.             CommandBufferPool.Release(cmd);
    29.         }
    30.  
     
  4. Nyarlathothep

    Nyarlathothep

    Joined:
    Jun 13, 2013
    Posts:
    398
    Does this allow you to insert a command buffer into the rendering pipeline for that camera like the old CameraEvent system? As I understand it customRender completely replaces the pipeline for a camera?
     
    murata_job likes this.
  5. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    264
    Hi, Currently the only entry point you have in HDRP is the one available in SRPs in general: https://docs.unity3d.com/ScriptReference/Rendering.RenderPipelineManager.html
    You have before/after frame and camera rendering.

    There are plans to add injection points with custom passes in HDRP (a bit like in Universal but with less injection points), you can have more details about this here: https://github.com/Unity-Technologies/ScriptableRenderPipeline/pull/4317.
    We'll probably add more injection points in the future but that's not yet planned.
     
    Nyarlathothep likes this.
  6. Nyarlathothep

    Nyarlathothep

    Joined:
    Jun 13, 2013
    Posts:
    398
    For our asset Wet Stuff we're injecting command buffers to modify the GBuffer (to change surfaces to appear to be wet). I think that PR probably doesn't offer the injection points we need (in CameraEvent terms we need BeforeReflections) but it looks like a move in the right direction!
     
    Last edited: Nov 4, 2019
    drawpixel likes this.