CapturePass.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. namespace UnityEngine.Rendering.Universal
  2. {
  3. /// <summary>
  4. /// Let customizable actions inject commands to capture the camera output.
  5. ///
  6. /// You can use this pass to inject capture commands into a command buffer
  7. /// with the goal of having camera capture happening in external code.
  8. /// </summary>
  9. internal class CapturePass : ScriptableRenderPass
  10. {
  11. RenderTargetHandle m_CameraColorHandle;
  12. const string m_ProfilerTag = "Capture Pass";
  13. public CapturePass(RenderPassEvent evt)
  14. {
  15. renderPassEvent = evt;
  16. }
  17. /// <summary>
  18. /// Configure the pass
  19. /// </summary>
  20. /// <param name="actions"></param>
  21. public void Setup(RenderTargetHandle colorHandle)
  22. {
  23. m_CameraColorHandle = colorHandle;
  24. }
  25. /// <inheritdoc/>
  26. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
  27. {
  28. CommandBuffer cmdBuf = CommandBufferPool.Get(m_ProfilerTag);
  29. var colorAttachmentIdentifier = m_CameraColorHandle.Identifier();
  30. var captureActions = renderingData.cameraData.captureActions;
  31. for (captureActions.Reset(); captureActions.MoveNext();)
  32. captureActions.Current(colorAttachmentIdentifier, cmdBuf);
  33. context.ExecuteCommandBuffer(cmdBuf);
  34. CommandBufferPool.Release(cmdBuf);
  35. }
  36. }
  37. }