back to table of contents

Shadows
download mac os x application and source code (64k)
Written monday october 22, 2001. Developed with apple's free developer tools on mac os 10.1
This document, images, source and application are the intellectual property of forrest briggs. You may freely use the source code i provide. Email me with questions or suggestions.

Shadows

Unlike in other kinds of 3d engine, shadows are very simple to do in a ray tracer. A point is in shadow if a ray from that point to the light source intersects any objects. In order to apply Diffuse shading, the point of intersection of a ray and a sphere has already been calculated. This point is the origin of the shadow ray. The direction of the shadow ray (which is the direction From the point of intersection to the light,) has also already been Calculated. One special concern when checking shadow rays for intersection is that any intersections found are only valid if they occur in between the origin of the ray and the light. Although It may not seem so, the distance from the origin of the shadow ray (the intersection,) to the light has already been calculated; it is the magnitude of the vector that becomes the direction Of the shadow ray. Discard any intersections that occur at a distance greater than this value. There is no need to perform any additional intersections once one intersection has been found (unless you are dealing with transparent objects, but that is an entirely more complex situation.)

Optimization

One technique that is sometimes use to accelerate shadow rays is caching. Since it doesnt matter which object a shadow ray intersects, whenever a shadow ray is found to intersect an object, Information about which object is stored. Then, the next time a shadow ray is being checked, the object that was previously intersected is tested first on the grounds that it is likely, due To spatial coherence, that it will be intersected again. I have not found this technique to increase speed very much, if at all, so it is not included in the example code. Shadow rays have The special property that they all point to the same location, which can be exploited by optimizations that apply to primary rays, which will be discussed later.