Graphics Reference
In-Depth Information
vectors: .rgba (for vectors as color), .xyzw (for vectors as geometry), and .stpq
(for vectors as texture coordinates). You can also use any subset of the symbolic
names to access parts of a vector. For example, aVertex.xyz gets you the first
three components of a vertex. aVertex.rgb looks wrong, but would get you
the same thing. Another new kind of vector access involves rearranging their
components, or “swizzling” them. Components can be swizzled by giving the
symbolic names of the components in changed order (e.g., c1.rgba = c2.abgr )
to rearrange their order.
GLSL shaders also extend the normal C functionality in adding new kinds
of type qualifiers for variables. The new qualifiers, and their meanings, are
const —a variable that is a compile-time constant and cannot be refer-
enced outside the shader that defines it. These variables cannot be used
on the left-hand side of an assignment operation under any circum-
stances. (This is the same as the C++ const.)
attribute —a variable, only used in a vertex shader, that is set by the
application per-vertex and is generally sent from the application to the
graphics card by OpenGL functions. Atribute variables may include the
traditional per-vertex values of model coordinates, color, normal, normal
matrix, or texture coordinates, but an application may define additional
atribute variables when needed.
uniform —a variable that is set outside a shader and can be changed at
most once per primitive.
in or out —variables used to communicate results from one shader
to another. An out variable is to get its value in the shader where it is
defined and be passed from that shader to the next shader further along
in the shader pipeline. It is a write-only variable in the shader where it
is defined. An in variable is to be received from a previous shader in the
shader pipeline and used in the shader where it is defined. It is a read-only
variable in the shader where it is defined. An in variable in a fragment
shader will be interpolated across the fragments in a graphics primitive.
This interpolation will be done in a perspective-corrected fashion; see [14].
Shaders can create their own functions, just like in C/C++, with their own
parameters and local variables. Another set of type qualifiers is used for func-
tion parameters for shaders. These are keyed to the role of the parameters in
the function, and are
in —a parameter of this type is intended to have a value when it is passed
into a function but is not to be changed in the function. It functions much
as a const variable would. Such parameters are intended to communicate
only from the calling function to the called function.
Search WWH ::




Custom Search