ShaderLab syntax: Properties
Manual     Reference     Scripting   
Reference Manual > Shader Reference > ShaderLab syntax: Shader > ShaderLab syntax: Properties

ShaderLab syntax: Properties

Shaders can define a list of parameters to be set by artists in Unity's material inspector. The Properties block in the shader file defines them.

Syntax

Properties { Property [Property ...] }
Defines the property block. Inside braces multiple properties are defined as follows.
name ("display name", Range (min, max)) = number
Defines a float property, represented as a slider from min to max in the inspector.
name ("display name", Color) = (number,number,number,number)
Defines a color property.
name ("display name", 2D) = "name" { options }
Defines a 2D texture property.
name ("display name", Rect) = "name" { options }
Defines a rectangle (non power of 2) texture property.
name ("display name", Cube) = "name" { options }
Defines a cubemap texture property.
name ("display name", Float) = number
Defines a float property.
name ("display name", Vector) = (number,number,number,number)
Defines a four component vector property.

Details

Each property inside the shader is referenced by name (in Unity, it's common to start shader property names with underscore). The property will show up in material inspector as display name. For each property a default value is given after equals sign:

Later on in the shader, property values are accessed using property name in square brackets: [name].

Example

Properties {
    // properties for water shader
    _WaveScale ("Wave scale", Range (0.02,0.15)) = 0.07 // sliders
    _ReflDistort ("Reflection distort", Range (0,1.5)) = 0.5
    _RefrDistort ("Refraction distort", Range (0,1.5)) = 0.4
    _RefrColor ("Refraction color", Color)  = (.34, .85, .92, 1) // color
    _ReflectionTex ("Environment Reflection", 2D) = "" {} // textures
    _RefractionTex ("Environment Refraction", 2D) = "" {}
    _Fresnel ("Fresnel (A) ", 2D) = "" {}
    _BumpMap ("Bumpmap (RGB) ", 2D) = "" {}
} 

Texture property options

The options inside curly braces of the texture property are optional. The available options are:

Example

// EyeLinear texgen mode example
Shader "Texgen/Eye Linear" {
    Properties {
        _MainTex ("Base", 2D) = "white" { TexGen EyeLinear }
    }
    SubShader {
        Pass {
            SetTexture [_MainTex] { combine texture }
        }
    }
} 

Page last updated: 2012-02-29