i
i
i
i
i
i
i
i
13.2. Instancing 307
else
k
r
=exp(−a
r
t)
k
g
=exp(−a
g
t)
k
b
=exp(−a
b
t)
if refract(d, −n, 1/n, t) then
c = t · n
else
return k ∗ color(p + tr)
R
0
=(n − 1)
2
/(n +1)
2
R = R
0
+(1− R
0
)(1 − c)
5
return k(R color(p + tr) + (1 −R) color(p + tt))
The code above assumes that the natural log has been folded into the constants
(a
r
,a
g
,a
b
).Therefract function returns false if there is total internal re-
flection, and otherwise it fills in the last argument of the argument
list.
13.2 Instancing
An elegant property of ray tracing is that it allows very natural instancing.The
basic idea of instancing is to distort all points on an object by a transformation
matrix before the object is displayed. For example, if we transform the unit circle
(in 2D) by a scale factor (2, 1) in x and y, respectively, then rotate it by 45
◦
,and
move one unit in the x-direction, the result is an ellipse with an eccentricity of
2 and a long axis along the (x = −y)-direction centered at (0, 1) (Figure 13.4).
The key thing that makes that entity an “instance” is that we store the circle and
the composite transform matrix. Thus, the explicit construction of the ellipse is
left as a future operation at render time.
Figure 13.4. An instance
of a circle with a series of
three transforms is an el-
lipse.
The advantage of instancing in ray tracing is that we can choose the space in
which to do intersection. If the base object is composed of a set of points, one of
which is p, then the transformed object is composed of that set of points trans-
formed by matrix M, where the example point is transformed to Mp.Ifwehave
araya + tb that we want to intersect with the transformed object, we can instead
intersect an inverse-transformed ray with the untransformed object (Figure 13.5).
There are two potential advantages to computing in the untransformed space (i.e.,
the right-hand side of Figure 13.5):
1. the untransformed object may have a simpler intersection routine, e.g., a
sphere versus an ellipsoid;