O'Reilly logo

Unity 3 Game Development HOTSHOT by Jate Wittayabundit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Cg/HLSL programming

This section presents a brief description of how to access the shader Properties in Cg/HLSL programming, and the data types and common methods used in Cg/HLSL programming.

Accessing shader properties in Cg/HLSL

Shader can be declared with properties in a Properties block. If you want to access some of those properties in a Cg/HLSL shader program, you need to declare a Cg/HLSL variable with the same name and a matching type.

Example:

Properties {
    _MainTex ("Texture", 2D) = "white" {}
  }

  SubShader {
    ......
    CGPROGRAM
    sampler2D _MainTex;
    ...

Property types to Cg/HLSL variable types are as follows:

  • Color and Vector properties map to float4 variables.
  • Range and Float properties map to float variables.
  • Texture properties map to sampler2D ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required