docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Inject a pass using a Scriptable Renderer Feature

    This section describes how to create a Scriptable Renderer Feature for a URP Renderer. A Scriptable Renderer Feature enqueues a ScriptableRenderPass instance every frame.

    You need to write a Scriptable Render Pass first.

    This walkthrough contains the following sections:

    • Create a scriptable Renderer Feature
    • Add the Renderer Feature to the the Universal Renderer asset
    • Enqueue the render pass in the custom renderer feature
    • Complete code for the scripts in this example

    Create a scriptable Renderer Feature

    1. Create a new C# script and name it MyRendererFeature.cs.

    2. In the script, remove the code that Unity inserted in the MyRendererFeature class.

    3. Add the following using directive:

      using UnityEngine.Rendering;
      using UnityEngine.Rendering.Universal;
      
    4. Create the MyRendererFeature class that inherits from the ScriptableRendererFeature class.

      public class MyRendererFeature : ScriptableRendererFeature    
      
    5. In the MyRendererFeature class, implement the following methods:

      • Create: Unity calls this method on the following events:

        • When the Renderer Feature loads the first time.

        • When you enable or disable the Renderer Feature.

        • When you change a property in the inspector of the Renderer Feature.

      • AddRenderPasses: Unity calls this method every frame, once for each camera. This method lets you inject ScriptableRenderPass instances into the scriptable Renderer.

    Now you have the custom MyRendererFeature Renderer Feature with its main methods.

    Below is the complete code for this step.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Rendering.Universal;
    
    public class MyRendererFeature : ScriptableRendererFeature
    {
        public override void Create()
        {
    
        }
    
        public override void AddRenderPasses(ScriptableRenderer renderer,
            ref RenderingData renderingData)
        {
    
        }
    }
    

    Add the Renderer Feature to the Universal Renderer asset

    Add the Renderer Feature you created to the the Universal Renderer asset. For information on how to do this, refer to the page How to add a Renderer Feature to a Renderer.

    Enqueue a render pass in the custom renderer feature

    In this section, you instantiate a render pass in the Create method of the MyRendererFeature class, and enqueue it in the AddRenderPasses method.

    This section uses the example RedTintRenderPass Scriptable Render Pass from the Write a Scriptable Render Pass page.

    1. Declare the following fields:

      [SerializeField] private Shader shader;
      private Material material;
      private RedTintRenderPass redTintRenderPass;
      
    2. In the Create method, instantiate the RedTintRenderPass class.

      In the method, use the renderPassEvent field to specify when to execute the render pass.

      public override void Create()
      {
          if (shader == null)
          {
              return;
          }
          material = CoreUtils.CreateEngineMaterial(shader);
          redTintRenderPass = new RedTintRenderPass(material);
      
          redTintRenderPass.renderPassEvent = RenderPassEvent.AfterRenderingSkybox;
      }
      
    3. In the AddRenderPasses method, enqueue the render pass with the EnqueuePass method.

      public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
      {
          if (renderingData.cameraData.cameraType == CameraType.Game)
          {
              renderer.EnqueuePass(redTintRenderPass);
          }
      }
      

    You can now add the Scriptable Renderer Feature to the active URP asset.

    For a full example, refer to Example of a complete Scriptable Renderer Feature.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)