using System; using UnityEngine.Scripting.APIUpdating; namespace UnityEngine.Rendering.Universal { /// /// You can add a ScriptableRendererFeature to the ScriptableRenderer. Use this scriptable renderer feature to inject render passes into the renderer. /// /// /// [ExcludeFromPreset] public abstract class ScriptableRendererFeature : ScriptableObject, IDisposable { [SerializeField, HideInInspector] private bool m_Active = true; /// /// 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. /// public bool isActive => m_Active; /// /// Initializes this feature's resources. This is called every time serialization happens. /// public abstract void Create(); /// /// Callback before cull happens in renderer. /// /// Renderer of callback. /// CameraData contains all relevant render target information for the camera. public virtual void OnCameraPreCull(ScriptableRenderer renderer, in CameraData cameraData) { } /// /// Injects one or multiple ScriptableRenderPass in the renderer. /// /// Renderer used for adding render passes. /// Rendering state. Use this to setup render passes. public abstract void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData); /// /// Callback after render targets are initialized. This allows for accessing targets from renderer after they are created and ready. /// /// Renderer used for adding render passes. /// Rendering state. Use this to setup render passes. public virtual void SetupRenderPasses(ScriptableRenderer renderer, in RenderingData renderingData) { } void OnEnable() { // UUM-44048: If the pipeline is not created, don't call Create() as it may allocate RTHandles or do other // things that require the pipeline to be constructed. This is safe because once the pipeline is constructed, // ScriptableRendererFeature.Create() will be called by ScriptableRenderer constructor. if (RenderPipelineManager.currentPipeline is UniversalRenderPipeline) Create(); } void OnValidate() { // See comment in OnEnable. if (RenderPipelineManager.currentPipeline is UniversalRenderPipeline) Create(); } /// /// Override this method and return true if the feature should use the Native RenderPass API /// internal virtual bool SupportsNativeRenderPass() { return false; } /// /// Override this method and return true that renderer would produce rendering layers texture. /// /// True if renderer is using deferred rendering mode /// True if renderer has Accurate G-Buffer Normals enabled /// Requeted event at which rendering layers texture will be produced /// Requested bit size of rendering layers texture /// internal virtual bool RequireRenderingLayers(bool isDeferred, bool needsGBufferAccurateNormals, out RenderingLayerUtils.Event atEvent, out RenderingLayerUtils.MaskSize maskSize) { atEvent = RenderingLayerUtils.Event.DepthNormalPrePass; maskSize = RenderingLayerUtils.MaskSize.Bits8; return false; } /// /// Sets the state of ScriptableRenderFeature (true: the feature is active, false: the feature is inactive). /// If the feature is active, it is added to the renderer it is attached to, otherwise the feature is skipped while rendering. /// /// The true value activates the ScriptableRenderFeature and the false value deactivates it. public void SetActive(bool active) { m_Active = active; } /// /// Disposable pattern implementation. /// Cleans up resources used by the renderer. /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } /// /// Called by Dispose(). /// Override this function to clean up resources in your renderer. /// /// protected virtual void Dispose(bool disposing) { } } }