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

Introduction to the shader programming language

3.0.4. Number and Slider Properties

This post is also available in…

These types of properties allow us to add numerical values ​​to our shader. Let’s suppose that we want to create a shader with functions of illumination where “zero” equals 0% illumination and “one” equals 100% illumination. We can create a range for this (e.g. Range (min, max)) and configure the minimum, maximum and default illumination values.

The following syntax declares numbers and sliders in our shader:

// name (“display name”, Range(min, max)) = defaultValue
// name (“display name”, Float) = defaultValue
// name (“display name”, Int) = defaultValue

Shader “InspectorPath / shaderName”
{
    Properties 
    {
       _Specular (“Specular”, Range(0.0, 1.1)) = 0.3
       _Factor (“Color Factor”, Float) = 0.3
       _Cid (“Color id”, Int) = 2
    } 
}

In the previous example we declared three properties, a “floating range” type called _Specular, another “floating scale” type called _Factor, and finally, an “integer” type called _Cid.

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-logo

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.