Graphics Reference
In-Depth Information
float length(genType x)
2
2
Returns the length of the vector
x
, ([]
x
0
+
x
[ ]
1
+
...).
float distance(genType p0,
genType p1)
Returns the distance between
p0
and
p1
:
length(p0 - p1)
.
float dot(genType x,
genType y)
Returns the dot product of
x
and
y
:
x[0]*y[0]+x[1]*y[1]+...
.
vec3 cross(vec3 x, vec3 y)
Returns the cross product of
x
and
y
,
xy yx
xy yx
xy yx
[][] [][]
[][] [][]
[][] [][]
12 12
20 20
01 01
−
−
−
.
genType normalize(genType x)
Returns a vector in the same direction as
x,
but with a length of 1,
or
x
x
.
Make
N
face in the direction of
Nref
. If
dot
(
Nref
,
I
) < 0 return
N
,
otherwise return -
N
.
genType faceforward(
genType N,
genType I,
genType Nref)
genType reflect(genType I,
genType N)
For the incident vector
I
and surface orientation
N
, returns the
reflection direction:
I
− 2
*
dot
(
N
,
I
)
*
N
. The normal vector
N
must
already be normalized in order to achieve the correct result.
genType refract(genType I,
genType N,
float eta)
For the incident vector
I
and surface normal
N
, and the ratio of
indices of refraction
eta
, return the refraction vector. The result is
computed by
k=1.0-eta*eta*(1.0-dot(N,I)*dot(N,I))
if (k < 0.0)
return genType(0.0)
else
return eta*I-(eta*dot(N,I)+sqrt(k))*N.
The incident vector
I
and the normal vector
N
must already be
normalized in order to achieve the correct result.