Graphics Reference
In-Depth Information
mat3(float, float, float,
float, float, float,
float, float, float)
Rows are first column, second column, and
third column, respectively.
mat4(loat,loat,loat,loat,
loat,loat,loat,loat,
loat,loat,loat,loat,
loat,loat,loat,loat)
Rows are first column, second column, third
column, and fourth column, respectively.
Rows are first column and second column,
respectively.
mat2x3(vec2, float,
vec2, float)
Even though GLSL offers these 2D matrix formats, it is sometimes convenient
to use simpler 1D arrays. For example, we can represent a 3 × 3 matrix
M
as three
separate
vec3
variables and then multiply M by a matrix
V
by using three dot
products.
There are many other ways to construct a matrix from vectors and scalars,
as long as there are enough components to initialize the matrix. The construc-
tion acts as though the matrix begins as an identity matrix (or a subset of an
identity matrix), and the new elements that are specified replace the originals.
For example, to construct a matrix from a matrix we might have the possibili-
ties given in the following table.
mat3x3(mat4x4)
Uses the upper-left 3
×
3 submatrix of the
mat4x4
matrix.
mat2x3(mat4x2)
Takes the upper-left 2 × 2 submatrix of the
mat4x2
, and sets
the last column to
vec2(0.)
.
mat4x4(mat3x3)
Puts the
mat3×3
matrix in the upper-left submatrix and sets
the lower right component to 1 and the rest to 0.
Functions Extended to Matrices and Vectors
Standard programming languages tend to have a number of numeric func-
tions and operators, including trigonometric functions, exponential functions,
number manipulation functions, and relational operators. In GLSL, most of
these can operate on vectors, as well as on scalar values.
The familiar bitwise integer functions
<<
,
>>
,
%
,
&
,
|
,
^
, and
~
are all avail-
able in GLSL and apply to both simple integer and
ivecN
data.
In the lists of functions below, we use the term
genType
to refer to any
scalar or vector data type that is appropriate for each function. In general, these
functions use
float
or
vecN
data, but you can use an integer type anywhere a
float type is needed, because GLSL allows that implicit type conversion.