Graphics Reference
In-Depth Information
GLSL also adds several new vector and matrix operators. There are
name set conventions for vectors that let you name components in computer-
graphics ways, and there are operations to construct vectors and matrices, and
to reorder vector components that give you much more flexible control over
these data objects. Overall, GLSL treats vectors and matrices much more like
data primitives than does C.
New Functions
GLSL includes many numeric functions that might be relatively easy to
write for yourself, but that when included, make their capabilities more
standardized across the developer world. These include floor , ceil , fract ,
mod (a generalized version of the familiar function), min , max , clamp , mix ,
step , and smoothstep . GLSL also includes several vector and matrix func-
tions to support common operations in a uniform way. These include the
dot and cross product for vectors, functions for the reflection and refrac-
tion vectors, and the transpose and outer product for matrices. These are
described fully later.
New Variable Types
GLSL introduces some new variable types: const , attribute , and uniform .
Const variables act as constants, much as if they were set with a #define state-
ment, only more strongly typed as they are in C and C++. Atribute variables
are per-vertex values passed to the vertex shader. Uniform variables let you
define graphics variables that do not vary across a primitive and make them
accessible to all shaders.
Shaders create a shared namespace, described above, by specifying the
variables to be included in the namespace. They do this by declaring out vari-
ables, treated as write-only and used to give variables values to be used in the
next shader in the pipeline, and in variables, treated as read-only and used
to read values in from the previous shader in the pipeline. An out variable
declared in, say, a vertex shader, can be used to set a value to be read in an in
variable of the same name declared in, say, a fragment shader.
There are some keywords that modify the behavior of in variables for a
fragment shader; these are flat , noperspective , and centroid . The keyword
flat indicates that values of the input variables are not to be interpolated
across a primitive. The usage is
flat in float variable_name;
Search WWH ::




Custom Search