Game Development Reference
In-Depth Information
Storage Qualifiers
Storage qualifiers indicate how variables will be used in the shader program. From this information,
the compiler can more efficiently process and store the shader variables.
Const: The const qualifier specifies a compile time constant or a read-only function
parameter.
Const int NumberLights = 3;
Attribute: The attribute qualifier specifies a linkage between a vertex shader and
the main OpenGL ES 2.0 program for per-vertex data. Some examples of the types
of variables where the attribute qualifier can be used are vertex position, vertex
textures, and vertex normal.
attribute vec3 aPosition;
attribute vec2 aTextureCoord;
attribute vec3 aNormal;
Uniform: The uniform qualifier specifies that the value does not change across the
primitive being processed. Uniform variables form the linkage between a vertex
or fragment shader and the main OpenGL ES 2.0 application. Some examples
of variables where the uniform qualifier would be appropriate are lighting values,
material values, and matrices.
uniform vec3 uLightAmbient;
uniform vec3 uLightDiffuse;
uniform vec3 uLightSpecular;
Varying: The varying qualifier specifies a variable that occurs both in the vertex
shader and fragment shader. This creates the linkage between a vertex shader and
fragment shader for interpolated data. These are usually values for the diffuse and
the specular lighting that will be passed from the vertex shader to the fragment
shader. Texture coordinates, if present, are also varying. The values of the diffuse and
specular lighting, as well as textures, are interpolated or “varying” across the object
the shader is rendering. Some examples of varying variables are the vertex texture
coordinate, the diffuse color of the vertex, and the specular color of the vertex.
varying vec2 vTextureCoord;
varying float vDiffuse;
varying float vSpecular;
 
Search WWH ::




Custom Search