Get an 20% OFF using the RELEASE code on your book purchase. For a limited time.

Introduction to the shader programming language

3.1.0. MPD Enum

This post is also available in…

This drawer is very similar to the KeywordEnum with the difference that it can define a “value/id” as an argument and pass this property to a command in our shader to change its functionality dynamically from the inspector. 

Its syntax is as follows:

[Enum(valor, id_00, valor, id_01, etc ...)] 
    _PropertyName (“Display Name”, Float) = 0

Enums do not use shader variants but are declared by command or function. To understand their implementation, we will perform the following operation:

Shader “InspectorPath / shaderName”
    // declare drawer
    [Enum(Off, 0, Front, 1, Back, 2)] 
        _Face (“Face Culling”, Float) = 0
        // pass the property to the command  
        Cull [_Face]
        Pass {} ...

As presented in this example, we declare a property type “Enum” called “_Face” and we pass as an argument the values: Off, 0, Front, 1, Back and 2. Then we add the property to the command “Cull” found in the SubShader; this way we can change the object face we want to render from the material inspector. In section 2.2.9 we will talk about the Cull command in detail.

Follow us to stay informed about all the latest news, updates, and more.

Join the group to share your experiences with other developers.

Subscribe to our channel and keep learning game dev!


Jettelly Team

We are a team of indie developers with more than 9 years of experience in video games. As an independent studio, we have developed Nom Noms in which we published with Hyperbeard in 2019. We are currently developing The Unity Shader Bible.

Follow us on our social networks.