설명 없음
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DepthBlitEdgePass.cs 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using UnityEngine;
  2. using UnityEngine.Rendering;
  3. using UnityEngine.Rendering.RenderGraphModule;
  4. using UnityEngine.Rendering.Universal;
  5. // This pass performs a blit operation with a Material. The input texture is set by the Renderer Feature.
  6. public class DepthBlitEdgePass : ScriptableRenderPass
  7. {
  8. class PassData
  9. {
  10. public TextureHandle source;
  11. public Material material;
  12. public Vector4 scaleBias;
  13. }
  14. private Vector4 m_ScaleBias = new Vector4(1f, 1f, 0f, 0f);
  15. private ProfilingSampler m_ProfilingSampler = new ProfilingSampler("DepthBlitEdgePass");
  16. private RTHandle m_DepthHandle; // The RTHandle of the depth texture, set by the Renderer Feature, only used in the Compatibility mode (non-RenderGraph path)
  17. private Material m_Material;
  18. public DepthBlitEdgePass(Material mat, RenderPassEvent evt)
  19. {
  20. renderPassEvent = evt;
  21. m_Material = mat;
  22. }
  23. public void SetRTHandle(ref RTHandle depthHandle)
  24. {
  25. m_DepthHandle = depthHandle;
  26. }
  27. #pragma warning disable 618, 672 // Type or member is obsolete, Member overrides obsolete member
  28. // Unity calls the Execute method in the Compatibility mode
  29. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
  30. {
  31. var cameraData = renderingData.cameraData;
  32. if (cameraData.camera.cameraType != CameraType.Game)
  33. return;
  34. RTHandle destination = cameraData.renderer.cameraColorTargetHandle;
  35. CommandBuffer cmd = CommandBufferPool.Get();
  36. using (new ProfilingScope(cmd, m_ProfilingSampler))
  37. {
  38. Blitter.BlitCameraTexture(cmd, m_DepthHandle, destination, m_Material, 0);
  39. }
  40. context.ExecuteCommandBuffer(cmd);
  41. cmd.Clear();
  42. CommandBufferPool.Release(cmd);
  43. }
  44. #pragma warning restore 618, 672
  45. // Unity calls the RecordRenderGraph method to add and configure one or more render passes in the render graph system.
  46. public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
  47. {
  48. UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
  49. UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
  50. DepthBlitFeature.TexRefData texRefData = frameData.Get<DepthBlitFeature.TexRefData>();
  51. if (cameraData.camera.cameraType != CameraType.Game)
  52. return;
  53. using (var builder = renderGraph.AddRasterRenderPass<PassData>("DepthBlitEdgePass", out var passData))
  54. {
  55. // Set the DepthHandle as a texture resource for this render graph instance
  56. TextureHandle source = texRefData.depthTextureHandle;
  57. // Set camera color as a texture resource for this render graph instance
  58. TextureHandle destination = resourceData.activeColorTexture;
  59. if (!source.IsValid() || !destination.IsValid())
  60. return;
  61. passData.source = source;
  62. passData.material = m_Material;
  63. passData.scaleBias = m_ScaleBias;
  64. builder.UseTexture(source, AccessFlags.Read); // Set the depth texture as the input
  65. builder.SetRenderAttachment(destination, 0, AccessFlags.Write); // Set the camera color as the output
  66. builder.SetRenderFunc((PassData data, RasterGraphContext context) =>
  67. {
  68. Blitter.BlitTexture(context.cmd, data.source, data.scaleBias , data.material, 0);
  69. });
  70. }
  71. }
  72. }