SceneViewDepthCopy.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. namespace UnityEngine.Rendering.Universal
  2. {
  3. internal class SceneViewDepthCopyPass : ScriptableRenderPass
  4. {
  5. private RenderTargetHandle source { get; set; }
  6. Material m_CopyDepthMaterial;
  7. const string m_ProfilerTag = "Copy Depth for Scene View";
  8. public SceneViewDepthCopyPass(RenderPassEvent evt, Material copyDepthMaterial)
  9. {
  10. m_CopyDepthMaterial = copyDepthMaterial;
  11. renderPassEvent = evt;
  12. }
  13. public void Setup(RenderTargetHandle source)
  14. {
  15. this.source = source;
  16. }
  17. /// <inheritdoc/>
  18. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
  19. {
  20. if (m_CopyDepthMaterial == null)
  21. {
  22. Debug.LogErrorFormat("Missing {0}. {1} render pass will not execute. Check for missing reference in the renderer resources.", m_CopyDepthMaterial, GetType().Name);
  23. return;
  24. }
  25. // Restore Render target for additional editor rendering.
  26. // Note: Scene view camera always perform depth prepass
  27. CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);
  28. CoreUtils.SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget);
  29. cmd.SetGlobalTexture("_CameraDepthAttachment", source.Identifier());
  30. cmd.EnableShaderKeyword(ShaderKeywordStrings.DepthNoMsaa);
  31. cmd.DisableShaderKeyword(ShaderKeywordStrings.DepthMsaa2);
  32. cmd.DisableShaderKeyword(ShaderKeywordStrings.DepthMsaa4);
  33. cmd.Blit(source.Identifier(), BuiltinRenderTextureType.CameraTarget, m_CopyDepthMaterial);
  34. context.ExecuteCommandBuffer(cmd);
  35. CommandBufferPool.Release(cmd);
  36. }
  37. }
  38. }