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.

ScriptableRendererFeature.cs 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using UnityEngine.Scripting.APIUpdating;
  3. namespace UnityEngine.Rendering.Universal
  4. {
  5. /// <summary>
  6. /// You can add a <c>ScriptableRendererFeature</c> to the <c>ScriptableRenderer</c>. Use this scriptable renderer feature to inject render passes into the renderer.
  7. /// </summary>
  8. /// <seealso cref="ScriptableRenderer"/>
  9. /// <seealso cref="ScriptableRenderPass"/>
  10. [ExcludeFromPreset]
  11. public abstract class ScriptableRendererFeature : ScriptableObject, IDisposable
  12. {
  13. [SerializeField, HideInInspector] private bool m_Active = true;
  14. /// <summary>
  15. /// Returns the state of the ScriptableRenderFeature (true: the feature is active, false: the feature is inactive). Use the method ScriptableRenderFeature.SetActive to change the value of this variable.
  16. /// </summary>
  17. public bool isActive => m_Active;
  18. /// <summary>
  19. /// Initializes this feature's resources. This is called every time serialization happens.
  20. /// </summary>
  21. public abstract void Create();
  22. /// <summary>
  23. /// Callback before cull happens in renderer.
  24. /// </summary>
  25. /// <param name="renderer">Renderer of callback.</param>
  26. /// <param name="cameraData">CameraData contains all relevant render target information for the camera.</param>
  27. public virtual void OnCameraPreCull(ScriptableRenderer renderer, in CameraData cameraData) { }
  28. /// <summary>
  29. /// Injects one or multiple <c>ScriptableRenderPass</c> in the renderer.
  30. /// </summary>
  31. /// <param name="renderer">Renderer used for adding render passes.</param>
  32. /// <param name="renderingData">Rendering state. Use this to setup render passes.</param>
  33. public abstract void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData);
  34. /// <summary>
  35. /// Callback after render targets are initialized. This allows for accessing targets from renderer after they are created and ready.
  36. /// </summary>
  37. /// <param name="renderer">Renderer used for adding render passes.</param>
  38. /// <param name="renderingData">Rendering state. Use this to setup render passes.</param>
  39. public virtual void SetupRenderPasses(ScriptableRenderer renderer, in RenderingData renderingData) { }
  40. void OnEnable()
  41. {
  42. // UUM-44048: If the pipeline is not created, don't call Create() as it may allocate RTHandles or do other
  43. // things that require the pipeline to be constructed. This is safe because once the pipeline is constructed,
  44. // ScriptableRendererFeature.Create() will be called by ScriptableRenderer constructor.
  45. if (RenderPipelineManager.currentPipeline is UniversalRenderPipeline)
  46. Create();
  47. }
  48. void OnValidate()
  49. {
  50. // See comment in OnEnable.
  51. if (RenderPipelineManager.currentPipeline is UniversalRenderPipeline)
  52. Create();
  53. }
  54. /// <summary>
  55. /// Override this method and return true if the feature should use the Native RenderPass API
  56. /// </summary>
  57. internal virtual bool SupportsNativeRenderPass()
  58. {
  59. return false;
  60. }
  61. /// <summary>
  62. /// Override this method and return true that renderer would produce rendering layers texture.
  63. /// </summary>
  64. /// <param name="isDeferred">True if renderer is using deferred rendering mode</param>
  65. /// <param name="needsGBufferAccurateNormals">True if renderer has Accurate G-Buffer Normals enabled</param>
  66. /// <param name="atEvent">Requeted event at which rendering layers texture will be produced</param>
  67. /// <param name="maskSize">Requested bit size of rendering layers texture</param>
  68. /// <returns></returns>
  69. internal virtual bool RequireRenderingLayers(bool isDeferred, bool needsGBufferAccurateNormals, out RenderingLayerUtils.Event atEvent, out RenderingLayerUtils.MaskSize maskSize)
  70. {
  71. atEvent = RenderingLayerUtils.Event.DepthNormalPrePass;
  72. maskSize = RenderingLayerUtils.MaskSize.Bits8;
  73. return false;
  74. }
  75. /// <summary>
  76. /// Sets the state of ScriptableRenderFeature (true: the feature is active, false: the feature is inactive).
  77. /// If the feature is active, it is added to the renderer it is attached to, otherwise the feature is skipped while rendering.
  78. /// </summary>
  79. /// <param name="active">The true value activates the ScriptableRenderFeature and the false value deactivates it.</param>
  80. public void SetActive(bool active)
  81. {
  82. m_Active = active;
  83. }
  84. /// <summary>
  85. /// Disposable pattern implementation.
  86. /// Cleans up resources used by the renderer.
  87. /// </summary>
  88. public void Dispose()
  89. {
  90. Dispose(true);
  91. GC.SuppressFinalize(this);
  92. }
  93. /// <summary>
  94. /// Called by Dispose().
  95. /// Override this function to clean up resources in your renderer.
  96. /// </summary>
  97. /// <param name="disposing"></param>
  98. protected virtual void Dispose(bool disposing)
  99. {
  100. }
  101. }
  102. }