Graphics Reference
In-Depth Information
We can write u = v * m ; this treats v as if it were a 1 × d matrix and per-
forms the correct operation of the dot product of v with each column of m .
We can write u = m * v ; this treats u and v as if they were d × 1 matrices
and performs the correct operation of the dot product of v with each row
of m .
We can write r = m * n ; this performs the dot product of each row of m
with each column of n to produce the matrix r .
In addition, the assignment operator = and relational equality and inequal-
ity operators == and != can be applied to entire arrays or structs, but the oper-
ands must be of the same size and, for structs, the same declared types. Other
relational functions are available for vectors, but they differ from the familiar
built-in relational operators. These are described later in this chapter.
Other familiar vector operations, the dot and cross products, are avail-
able through the built-in dot and cross product operations that are described
fully later in this chapter when we present GLSL's matrix functions. These
include several other useful capabilities. For example, if you should want the
componentwise scalar product of two matrices, you will need to use the new
matrix function matrixCompMult . Or if you should want to do an outer product
of two vectors (the outer product of two vectors u , v of dimension n is defined
as though u has dimension n × 1 and v has dimension 1 × n and you are com-
puting the matrix product [ u times v ]), you can use the new matrix function
outerProduct .
New Functions
As described in previous sections, many common functions from C are also
available in GLSL. However, languages such as C do not focus on graphics and
so have few functions to handle geometry and matrix data. GLSL provides
several new functions to do this. The list here is long, but is broken out into
several different areas, as they are in the language specification.
Geometric Functions
GLSL supports a number of functions to support geometric operations. These
have an obvious application for graphics, since many of the basic graphical
operations basically manipulate geometry. These functions include the famil-
iar scalar functions for length and dot product, and the familiar vector opera-
tions for cross product and normalization. They also include less familiar vec-
tor operations for reflection, refraction, and faceforward that can be very use-
ful.
Search WWH ::




Custom Search