Graphics Reference
In-Depth Information
{ Next, shoot the refracted ray }
if TransparencyOf (fromObjP) > minTransparency then
begin
if not (TotalInternalReflection (fromN,viewV)) then
begin
refractedRay := MkRefractedRay (viewV,fromPt,fromN,fromObj);
FirstIntersection2 (refractedRay,newPt,newN,newObjP);
if newObjP π nil then
light := light + refr*Shade (fromPt,fromObj,newPt,newN,newObjP);
end
end
end ;
return (light);
end ; { Shade }
{ The functions MkReflectedRay and MkRefractedRay return the appropriate ray }
procedure FirstIntersection2 ( ray r; ref pnt3d hitPt, hitN; ref shape pointer hitObjP)
{ The only difference between this procedure and FirstIntersection1 is that we use
three-dimensional bounding boxes rather than two-dimensional boxes }
Algorithm 10.2.2. Continued
Bounding boxes help in determining the intersection of a ray with an object, but
perhaps there was no need to consider that object in the first place. In other words,
we should try to mark those parts of space that contain no objects at all and take
advantage of spatial coherence . For example, using a median cut scheme that is gen-
erated automatically by the program we can create a top-down binary tree obtained
by sorting objects by the x-coordinate of some different coordinate axes at each level
and using the median value to partition the objects. If one were to sort on all three
coordinates x, y, and z simultaneously , one would get a hierarchy similar to that of
an octree. See [Glas84] and [FuTI86]. Alternatively, Sung and Shirley ([SunS92])
describe how a BSP tree can be used and compare this method to others. Subse-
quently, Havran et al. ([HKBZ97]) showed that one can speed up the traversal sub-
stantially if one uses an orthogonal BSP tree and ensures that statistically more
common cases are handled more efficiently. Another way to use coherence is to alter-
nate scanning from left-to-right and right-to-left. In that way one can use coherency
at the ends of scan lines to make intersection computations more efficient. For a more
detailed discussion of ray tracing speed-ups see [WatW92].
The simple ray-tracing program described in Algorithm 10.2.1 runs into the old
problem of aliasing, that is, the problem of not sampling enough. For example, we
only sent out as many primary rays as there are pixels. This means that some small
objects may not show up because they “fell through the crack.” See Figure 10.2. Two
Search WWH ::




Custom Search