CapturePass.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. private static readonly ProfilingSampler m_ProfilingSampler = new ProfilingSampler(m_ProfilerTag);
  14. public CapturePass(RenderPassEvent evt)
  15. {
  16. base.profilingSampler = new ProfilingSampler(nameof(CapturePass));
  17. renderPassEvent = evt;
  18. }
  19. /// <summary>
  20. /// Configure the pass
  21. /// </summary>
  22. /// <param name="actions"></param>
  23. public void Setup(RenderTargetHandle colorHandle)
  24. {
  25. m_CameraColorHandle = colorHandle;
  26. }
  27. /// <inheritdoc/>
  28. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
  29. {
  30. CommandBuffer cmdBuf = CommandBufferPool.Get();
  31. using (new ProfilingScope(cmdBuf, m_ProfilingSampler))
  32. {
  33. var colorAttachmentIdentifier = m_CameraColorHandle.Identifier();
  34. var captureActions = renderingData.cameraData.captureActions;
  35. for (captureActions.Reset(); captureActions.MoveNext();)
  36. captureActions.Current(colorAttachmentIdentifier, cmdBuf);
  37. }
  38. context.ExecuteCommandBuffer(cmdBuf);
  39. CommandBufferPool.Release(cmdBuf);
  40. }
  41. }
  42. }