Graphics Reference
In-Depth Information
Figure 10.1.
Ray-tracing rays.
for all
pixels p
do
begin
Define the ray R(p) which starts at the eye and goes in the
direction determined by p in world coordinates;
Find the intersections of R(p) with all objects in the world;
Determine which intersection is closest to the eye;
Determine the color of the light returning to the eye from that
point;
Set the value of p to that color;
end
;
To determine the color at the pixel, one needs to determine all possible light rays that
arrive at the corresponding point in the world. This reduces to recursively sending
out a number of secondary rays.
The ray-tracing program described in this section will keep track of four differ-
ent rays. See Figure 10.1(a). A
pixel ray
is the ray “from” the eye to the point in the
view plane determined by a pixel. A
reflection ray
is a ray that carries reflected light
to a point on an object. A
transparency ray
is a ray that carries light (the
transmitted
light
) to a point on an object from “within” it. Finally, a
shadow ray
is the ray from a
point on an object to a light source. Shadow rays are used to determine if a point is
in the shade of another object. As mentioned in the last chapter, shadow information
is important for making pictures look realistic. In Figure 10.1(a) we assume that
objects
W
and
Y
are transparent whereas objects
X
and
Z
are not, that is, the latter
two objects do not allow any light to pass through them. In the figure, E is a pixel ray.
R
1
is the reflection of E at a point on object
W
and T
1
is the transparency ray. S
1
and
S
2
are the shadow rays to the two light sources A and B. The fact that S
2
intersects
Z
means that
Z
casts a shadow on
W
. The ray T
1
hits object
X
and is reflected along R
2
.
Two shadow rays S
3
and S
4
are spawned. The ray R
1
hits object
Y
and generates a
reflected ray R
3
and a transparency ray T
2
. The two shadow rays here are S
5
and S
6
.
The ray tree is shown in Figure 10.1(b).
Assume that the viewport is the rectangle [XMIN,XMAX] ¥ [YMIN,YMAX] and
that I[i,j] specifies the intensity value of the (i-j)th pixel in the frame buffer. Algorithm