Version: 2020.3
ShaderLab
ShaderLab: defining material properties
How do you use documentation throughout your workflow? Share your experience with us by taking this survey.

ShaderLab: defining a Shader object

To define a ShaderA program that runs on the GPU. More info
See in Glossary
object in ShaderLab, use a Shader block. This page contains information on using Shader blocks.

For information on how a Shader object works, and the relationship between Shader objects, SubShaders and Passes, see Shader objects introduction.

Overview

A Shader object is a Unity-specific concept; it is a wrapper for shader programs and other information. It lets you define multiple shader programs in the same file, and tell Unity how to use them.

A Shader object has a nested structure; it organizes information into structures called SubShaders and Passes.

Render pipeline compatibility

Feature name Built-in Render Pipeline Universal Render Pipeline (URP) High Definition Render Pipeline (HDRP) Custom SRP
ShaderLab: Shader block Yes Yes Yes Yes

Using the Shader block

Inside the Shader block, you can:

Signature Function
Shader "<name>"
{
    <optional: Material properties>
    <One or more SubShader definitions>
    <optional: custom editor>
    <optional: fallback>
}
Defines a Shader object with a given name.

Examples

This example code demonstrates the basic syntax and structure of a Shader object. The example Shader object has a single SubShader that contains a single pass. It defines Material properties, a CustomEditor, and a Fallback.

Shader "Examples/ShaderSyntax"
{
    CustomEditor = "ExampleCustomEditor"

    Properties
    {
        // Material property declarations go here
    }
    SubShader
    {
        // The code that defines the rest of the SubShader goes here

        Pass
        {
           // The code that defines the Pass goes here
        }
    }

    Fallback "ExampleFallbackShader"
}

For step by step guidance on creating working shaders in different render pipelines, see the following pages:

ShaderLab
ShaderLab: defining material properties