Tuesday, April 24, 2012

ShaderLab: Day 1 (Properties & SubShaders)

For the next 7 days I will be blogging about my ShaderLab findings,

PROPERTIES
Shaders can define a list of parameters to be set by the artists in the material inspector.

Syntax:there are a only few things I need to look out for when setting up properties:
  • When setting up Properties you begin the section with:
    Properties
    {
           Property [Property]
    }
  • Some of the properties that you can include are as follows:
    • name = variable Name that is used in code
    • display name = the name that is showed in the inspector
    • name( "display name", Range (min, max)) = number)
      • example: _WaveScale("Wave scale", Range(0.02, 0.15)) = 0.07
        // sliders default is 0.07
    • name("display name", Color) = (number, number, number, number)
      • example: _RefractionColor("Refraction Color", Color) = (0.34, 0.85, 0.92,1)
        // this is a color, where the last value is the alpha color
    • name("display name", 2D) = "name"{ options }
      • example: _Fresnel{"Fresnel (A)", 2D) = "" { }
    • name("display name", Rect) = "name" {options}
      • example: _ReflectiveRect( "Reflective Rectangle, Rect) = "" { }
    • name("display name", Cube) = "name" {options}
      • example: _CubeMap ("Cube Map", Cube) = "" { }
    • name("display name", Float) = number
      • example: _RippleFrequency( "Ripple Frequency", Float) = 2.0
        //2 is the default value
    • name("display name", Vector) = (number, number, number, number)
      • example: _InfluenceVector("Influence Vector", Vector) = (0.2,0.0,0.0,1.0)
    • *Special Note: in the options field -> { options } here are the available options
      • TexGen texgenmode -> Automatic texture coordinate generation mode
        for the texture. TexGen is ignored if custom vertex programs are used.
      • LightmapMode -> Texture will be affected by pre-renderer lightmap parameters.
        That is, the texture to use can be not  in the material, but taken from the settings of the Renderer instead.
SUBSHADERS

Each shader in Unity consists of a list of subshaders. When Unity has to display a mesh it will find the shader to use and pick the first subshader that runs on the user's graphics card.

Syntax:
  • SubShader
    {
         [Tags] [CommonState] Passdef [Passdef.. ]}
         //defines the subshader as optional tags, common state and a list of pass definitions
    }
A subshader defines a list of rendering passes and optionally setup any state that is common to all passes. Additionally, subshader specific Tags can be set up. All tags can be found here: TAGS. When Unity chooses which subshader to render with it renders the object once for each Pass defined. As each render of the object is an expensive operation. The shader must be defined in the least number of passes possible. Sometimes on some graphics hardware the needed effect can't be done in a single pass.

No comments:

Post a Comment