- Intro to Basic Ray Tracing Algorithm
- Sampling
- Ray - Surface Intersection Routines
- Precision Problems
- Color Calculation

for(each pixel (sample) on the viewing area) { for(each primitive in the world model) { if(ray-pixel intersection) { select the frontmost intersection; recursively trace the relection and refraction rays; calculate color; } } }

The entire process of sampling can be thought of in the following four steps:

- Continuous 2D Signal - computer model which is defined at all points
- Sampling - Measuring rays
- Discrete 2D Image - Collection of all ray-color data
- Continuous 2D Image - an apporoximation, caused by averaging the color data for all the rays in a given pixel)

Different techniques are used for sampling to attempt to provide as accurate as representation as possible for a world which cannot be completely represented visually by a discrete computer. In other words, different sampling techniques are used to try to ensure that the model created in step 4 from the discrete date in step 3 closely resembles a real world view of the model described in step1.

The first step in calculating Ray-Surface Intersection is to obtain a mathematical model for the image. The image can be defined in two ways as follows. [These two images are re-produced, with permission, from the Stanford Computer Graphics Lab Web Site @ http://graphics.stanford.edu. Reproduction is prohibited.]

For example, an infinite plane can be defined in both of these ways as follows.

Once we have a mathematical model of every primitive in the scene, we must test each primitive for intersection with each ray that we are tracing. All these calculations, which must be done recursively until the rays end cause ray tracing to be a very computationally intensive process.

These intersection problems can be solved algebraically, using a parametric representation of the primitive and the ray. The solution is not only whether the two intersect, but also, if there is an intersection, the exact co-ordinates of the intersection. The ray-tracer can then use information about that point on the model to calculate the appropriate color that that object contributes to the ray.

There are methods available to avoid this incorrect shadowing.

- Because the last intersection point of any sphere is known, we can pass a boolean flag to the ray tracing function telling it is the ray about to be calculated originates from a surface of a primitive.
- More simply, we can assume that all rays starting within a certain tolerance (for example 0.00001 inches) of the surface of a primitive actually lie on that surface. This number must be lower for extremely small, intricate models.
- One can take the given intersection point and use it as the origin for a ray which continues in the same direction as the calculated ray. In this way, we can find a more accurate intersection point, that will not be misinterpreted as underneath the surface of an object. This method must still be used in conjunction with a tolerance factor, but it does allow the progam to be certain that the final calculated point of intersection lies within a certain distance of the actual point.
- The ray tracer can also move new rays it generates to the appropriate side of the sphere. By following the normal to the surface, one can move the origin of a new ray to the appropriate side of the surface (the inside for refraction rays, the outside for reflection rays)

Table of Contents