Graphics Reference
In-Depth Information
GLSL's built-in Boolean scalar and vector types are bool , bvec2 , bvec3 ,
and bvec4 . The main value in Boolean vectors is their ability to support logical
operations on vectors, and thus to parallelize some logical tests.
GLSL supports a number of matrix types. For square matrices, mat2 , mat3 ,
and mat4 can be used for square floating-point matrices of dimension 2 × 2,
3 × 3, or 4 × 4, respectively. Using explicit matrix types rather than simple arrays
lets you take advantage of GLSL's many matrix operations and functions.
There are also matrix types that define the dimensions explicitly by listing
both dimensions in the declaration. Thus, GLSL has mat2x2 , mat2x3 , mat2x4 ,
mat3x2 , mat3x3 , mat3x4 , mat4x2 , mat4x3 , and mat4x4 floating-point matrix
types. When the two dimensions are equal, this is the same as the declarations
above ( mat2x2 is the same as mat2 , for example). Using these matrix types lets
you use GLSL's matrix operations on non-square matrices. Note that there is
no declaration of mat1xN or matNx1 arrays; when a one-dimensional array is
needed, you can usually use a simple vecN in its place.
Name Sets
GLSL supports some standard name sets for vector components that are used
for notational convenience. For a vec4 variable, you can use ( x , y , z , w ) if you
want to refer to components for geometry, ( r , g , b , a ) if you want to refer to
components for color, or ( s , t , p , q ) if you want to refer to components for tex-
ture coordinates. The name set you choose need not depend on the context;
you can use ( x , y , z , w ) to refer to colors if you like, for example. (Note that the
leter r for texture coordinates has been replaced by p to avoid confusion with
the leter r for red.) In general, you should be careful to avoid name sets that
imply such meanings when choosing name sets for vectors other than geom-
etry, RGBA color, or texture.
The component selection syntax allows multiple components to be
selected by appending their names (which must be from the same name set)
after the period ( . ). So with a declaration vec4 v4 , for example, we have the
examples given in the table below.
v4.rgba Is a vec4 and is the same as just using v4 .
v4.rgb Is a vec3 made from the first three components of v4 .
v4.b Is a float whose value is the third component of v4 ; also v4.z or v4.p .
v4.xz Is a vec2 made from the first and third components of v4 ; also v4.rb or
v4.sp .
v4.xgba Is illegal because the component names do not come from the same set.
Search WWH ::




Custom Search