No Description
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.

NewRendererFeature.cs.txt 4.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using UnityEngine;
  2. using UnityEngine.Rendering;
  3. using UnityEngine.Rendering.Universal;
  4. using UnityEngine.Rendering.RenderGraphModule;
  5. public class #SCRIPTNAME# : ScriptableRendererFeature
  6. {
  7. class CustomRenderPass : ScriptableRenderPass
  8. {
  9. // This class stores the data needed by the RenderGraph pass.
  10. // It is passed as a parameter to the delegate function that executes the RenderGraph pass.
  11. private class PassData
  12. {
  13. }
  14. // This static method is passed as the RenderFunc delegate to the RenderGraph render pass.
  15. // It is used to execute draw commands.
  16. static void ExecutePass(PassData data, RasterGraphContext context)
  17. {
  18. }
  19. // RecordRenderGraph is where the RenderGraph handle can be accessed, through which render passes can be added to the graph.
  20. // FrameData is a context container through which URP resources can be accessed and managed.
  21. public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
  22. {
  23. const string passName = "Custom Render Pass";
  24. // This adds a raster render pass to the graph, specifying the name and the data type that will be passed to the ExecutePass function.
  25. using (var builder = renderGraph.AddRasterRenderPass<PassData>(passName, out var passData))
  26. {
  27. // Use this scope to set the required inputs and outputs of the pass and to
  28. // setup the passData with the required properties needed at pass execution time.
  29. // Make use of frameData to access resources and camera data through the dedicated containers.
  30. // Eg:
  31. // UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
  32. UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
  33. // Setup pass inputs and outputs through the builder interface.
  34. // Eg:
  35. // builder.UseTexture(sourceTexture);
  36. // TextureHandle destination = UniversalRenderer.CreateRenderGraphTexture(renderGraph, cameraData.cameraTargetDescriptor, "Destination Texture", false);
  37. // This sets the render target of the pass to the active color texture. Change it to your own render target as needed.
  38. builder.SetRenderAttachment(resourceData.activeColorTexture, 0);
  39. // Assigns the ExecutePass function to the render pass delegate. This will be called by the render graph when executing the pass.
  40. builder.SetRenderFunc((PassData data, RasterGraphContext context) => ExecutePass(data, context));
  41. }
  42. }
  43. // NOTE: This method is part of the compatibility rendering path, please use the Render Graph API above instead.
  44. // This method is called before executing the render pass.
  45. // It can be used to configure render targets and their clear state. Also to create temporary render target textures.
  46. // When empty this render pass will render to the active camera render target.
  47. // You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
  48. // The render pipeline will ensure target setup and clearing happens in a performant manner.
  49. public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
  50. {
  51. }
  52. // NOTE: This method is part of the compatibility rendering path, please use the Render Graph API above instead.
  53. // Here you can implement the rendering logic.
  54. // Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers
  55. // https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html
  56. // You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline.
  57. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
  58. {
  59. }
  60. // NOTE: This method is part of the compatibility rendering path, please use the Render Graph API above instead.
  61. // Cleanup any allocated resources that were created during the execution of this render pass.
  62. public override void OnCameraCleanup(CommandBuffer cmd)
  63. {
  64. }
  65. }
  66. CustomRenderPass m_ScriptablePass;
  67. /// <inheritdoc/>
  68. public override void Create()
  69. {
  70. m_ScriptablePass = new CustomRenderPass();
  71. // Configures where the render pass should be injected.
  72. m_ScriptablePass.renderPassEvent = RenderPassEvent.AfterRenderingOpaques;
  73. }
  74. // Here you can inject one or multiple render passes in the renderer.
  75. // This method is called when setting up the renderer once per-camera.
  76. public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
  77. {
  78. renderer.EnqueuePass(m_ScriptablePass);
  79. }
  80. }