Version: 2022.3
Language : English
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 ShaderLabUnity’s language for defining the structure of Shader objects. More info
See in Glossary
code to assign a name to a Pass. For information on defining Passes, see ShaderLab: defining a Pass. For information on how a ShaderA program that runs on the GPU. More info
See in Glossary
object works, and the relationship between Shader objectsAn instance of the Shader class, a Shader object is container for shader programs and GPU instructions, and information that tells Unity how to use them. Use them with materials to determine the appearance of your scene. More info
See in Glossary
, 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.

Render pipeline compatibility

Feature name Built-in Render PipelineA series of operations that take the contents of a Scene, and displays them on a screen. Unity lets you choose from pre-built render pipelines, or write your own. More info
See in Glossary
Universal Render Pipeline (URP) High Definition Render Pipeline (HDRP) Custom SRP
ShaderLab: Name block Yes Yes Yes Yes

Using the Name block

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

Signature Function
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# scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary
, 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
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。