Version: 2021.1
ShaderLab: defining a Pass
ShaderLab: assigning tags to a Pass

ShaderLab: assigning a name to a Pass

This page contains information on using a Name block in your ShaderLab code to assign a name to a Pass. For information on defining Passes, see ShaderLab: defining a Pass. For information on how a Shader object works, and the relationship between Shader objects, SubShaders and Passes, see Shader object fundamentals.

A Pass can have a name. You need to reference a Pass by name in the UsePass command, and in some C# APIs. The name of a Pass is visible in the Frame Debugger tool.


Feature name Built-in Render Pipeline Universal Render Pipeline (URP) 高清渲染管线 (HDRP) Custom SRP
ShaderLab: Name block

Using the Name block

To assign a name to a Pass in ShaderLab, you place a Name block inside a Pass block.

Signature 功能
Name "<name>" Sets the name of the Pass.

Internally, Unity converts the name to uppercase. When you reference the name in ShaderLab code, you must use the uppercase variant; for example, if the value is “example”, you must reference it as EXAMPLE.

If more than one Pass in the same SubShader has the same name, Unity uses the first Pass in the code.

Using the Pass name with C# scripts

To access the name of a Pass from C# scripts, you can use APIs such as Material.FindPass, Material.GetPassName, or ShaderData.Pass.Name.

Note: Material.GetShaderPassEnabled and Material.SetShaderPassEnabled do not reference Passes by name; instead, they reference Passes using the value of the LightMode tag.


This example code creates a Shader object called ContainsNamedPass, which contains a Pass called ExampleNamedPass.

Shader "Examples/ContainsNamedPass"
              Name "ExampleNamedPass"
              // The rest of the code that defines the Pass goes here.

You can then use the following C# code to query the name of this Pass:

using UnityEngine;

public class GetPassName : MonoBehaviour
    // Place this script on a GameObject with a MeshRenderer component
    void Start() {
        // Get the material
        var material = GetComponent<MeshRenderer>().material;

        // Get the name of the first Pass in the active SubShader
        // of the Shader object assigned to the material
        var passName = material.GetPassName(0);

        // Print the name to the console

ShaderLab: defining a Pass
ShaderLab: assigning tags to a Pass