Graphics Reference
In-Depth Information
Step function at the value of edge. Returns 0.0 if
x
<
edge
,
otherwise returns 1.0.
genType step(genType edge,
genType x)
genType step(float edge,
genType x)
genType smoothstep( genType edge0,
genType edge1,
genType x)
genType smoothstep( float edge0,
float edge1,
genType x)
Returns 0.0 if
x
<=
edge0
and 1.0 if
x
>=
edge1
, and performs
smooth Hermite interpolation between 0. and 1. when
edge0
<
x
<
edge1
. This is useful in cases where you would
want a threshold function with a smooth transition. This is
equivalent to
genType t;
t = clamp((x - edge0)/
(edge1 - edge0), 0., 1.);
return 3.*t*t - 2.*t*t*t;
Results are undefined if
edge0
>
edge1
.
Operations Extended to Matrices and Vectors
The traditional primitive operators, sum (+), difference (-), product (*), and
quotient (/), operate only on scalar data in most languages. In GLSL, this is
extended in a natural way to vector and matrix data. There are two different
cases to consider here.
Sums, differences, and quotients act componentwise when
•
One operand is a scalar and one is either a vector or matrix, or
•
Both are vectors or matrices.
Products act componentwise when
•
One operand is a scalar and one is either a vector or matrix, or
•
Both are vectors.
Note that if
u
and
v
are vectors,
u
*
v
is
not
a dot product! This product
u
*
v
is just a componentwise product and is still a vector. If you are trying to get
a dot product, use
dot( )
instead. In order to compute a product of vectors
or matrices, of course, both operands must have the same dimensions and
appropriate types. The result is a vector or matrix of the appropriate size and
type.
Products of a vector and a matrix, or of two matrices, are different; they
do not perform scalar operations, but perform the correct linear algebra opera-
tions on their operands. For vectors
u
,
v
and matrices
m
,
n
,
r
(always assuming
appropriate dimensions so the operations make sense),