Accessing shader properties in Cg
Manual     Reference     Scripting   
Reference Manual > Shader Reference > Writing vertex and fragment shaders > Accessing shader properties in Cg

Accessing shader properties in Cg

Shader declares it's properties in a Properties block. If you want to access some of those properties in a Cg shader program, you need to declare a Cg variable with the same name and a matching type. An example is provided in Shader Tutorial: Vertex and Fragment Programs.

For example these shader properties:

_MyColor ("Some Color", Color) = (1,1,1,1) 
_MyVector ("Some Vector", Vector) = (0,0,0,0) 
_MyFloat ("My float", Float) = 0.5 
_MyTexture ("Texture", 2D) = "white" {} 
_MyCubemap ("Cubemap", CUBE) = "" {} 

would be declared for access in Cg code as:

float4 _MyColor;
float4 _MyVector;
float _MyFloat; 
sampler2D _MyTexture;
samplerCUBE _MyCubemap;

Cg can also accept uniform keyword, but it is not necessary:

uniform float4 _MyColor;

Property types in ShaderLab map to Cg variable types this way:

Page last updated: 2008-05-10