Graphics Reference
In-Depth Information
integer
i, j;
ray
r;
{ defines starting point and direction of ray }
point eyePt, hitPt;
shape pointer hitObjP;
real array
I [XMIN .. XMAX, YMIN .. YMAX];
for i:=YMIN to YMAX do
for j:=XMIN to XMAX do
begin
ComputeRay (i,j,r);
FirstIntersection1 (r,hitPt,hitN,hitObjP);
if hitObjP π nil
then I[i,j] := Shade (eyePt, nil ,hitPt,hitN,hitObjP,1)
else
I[i,j] := background
end ;
procedure ComputeRay ( integer i, j; ref ray r)
{ Computes the ray r (in world coordinates) from the eye defined by the (i,j)th pixel }
procedure FirstIntersection1 ( ray r; ref point hitPt, hitN; ref shape pointer hitObjP)
{ Returns a pointer hitObjP to the closest object intersected by the ray r, the point hitPt
on that object where the ray intersects it, and the surface normal hitN at that point.
Use bounding boxes for projected objects in view plane to speed up computation. }
Algorithm 10.2.1.
A ray-tracing program.
10.2.1 shows a more detailed ray-tracing program. The Shade function is shown in
Algorithm 10.2.2. There we further assume that each object has associated with it two
fields - shininess and transparency - which indicate if it is shiny or transparent
enough to warrant sending out new reflection and transparency rays, respectively. See
[Hill90]. For simplicity we treat intensity as just a single real number in both algo-
rithms even though it has three components, for red, green, and blue. A real algo-
rithm would have to make three separate computations. For a more sophisticated
ray-tracing program using OpenGL, see [Hill01].
To speed up a ray-tracing program one needs to reduce the number of ray-object
intersection computations. One thing that is usually done is to use bounding boxes
or other bounding objects. More generally, one uses a hierarchical structure for the
bounding objects. For example, in the case of a table one might have a bounding box
for the whole table, and, if a ray intersected this box, then one would next check for
intersections with bounding boxes for the legs and top. Kay and Kajiya ([KayK86])
discuss the properties such a hierarchy should have and how one can construct it. A
natural hierarchy of bounding objects can be gotten by mimicking the hierarchy or
tree structure of the parts of an object.
Search WWH ::




Custom Search