Version: Unity 6 (6000.0)
Language : English
Create a Scriptable Renderer Feature in URP
Example of a complete Scriptable Renderer Feature in URP

Apply a Scriptable Renderer Feature to a specific camera type in URP

This guide covers how to apply a Scriptable Renderer Feature to a specific cameraA component which creates an image of a particular viewpoint in your scene. The output is either drawn to the screen or captured as a texture. More info
See in Glossary
type.

This method allows you to control which cameras the effect of a Scriptable Renderer Feature applies to. This is particularly relevant when a project uses additional cameras to render elements such as reflections where the use of the Scriptable Renderer Feature could lead to unexpected results.

You can add logic to the Scriptable Renderer Feature script to check for a specific camera type, before the Scriptable Renderer Feature applies the effect.

This guide is split into the following sections:

Prerequisites

This guide assumes that you already have a complete Scriptable Renderer Feature to work with. If you do not, refer to How to Create a Custom Renderer Feature.

Apply Scriptable Renderer Feature to Game Cameras

This script applies the Scriptable Renderer Feature to a specific camera type. In this example, it applies the feature only to Game cameras.

  1. Open the C# script of the Scriptable Renderer Feature you want to apply to the cameras.

  2. In the AddRenderPasses method, add the following if statement:

    if (renderingData.cameraData.cameraType == CameraType.Game)
    
  3. Add the necessary render passes from the Scriptable Renderer Feature to the renderer with the EnqueuePass method as shown below.

    if (renderingData.cameraData.cameraType == CameraType.Game)
    {
        renderer.EnqueuePass(yourRenderPass);
    }
    

This Scriptable Renderer Feature now only applies to Cameras with the Game camera type.

Note: Be aware that URP calls the AddRenderPasses method at least once per camera per frame so it is best to minimise complexity here to avoid performance issues.

Additional resources

Create a Scriptable Renderer Feature in URP
Example of a complete Scriptable Renderer Feature in URP