Building a Ray Tracer - Page One

For simplicity, all scenes are described in screen coordinates. The view plane coincides with the screen plane and the view window goes from (0, 0, 0) in the upper left to (433, 453, 0) in the lower right. The objects (all spheres in these first pictures) are placed between the screen and the viewer. The direction from the screen toward the viewer is the positive z-axis.

Only Ambient Light

For each pixel to be colored, a ray is followed to the viewer. The color of the sphere, intersecting that ray, that is nearest to the viewer determines the pixel color. If no sphere is intersected, a medium gray is used. The light source does not affect the scene. There is no shading on the spheres.

Diffuse Light

For each pixel to be colored, a ray is followed to the viewer and the point of intersection with an object that is nearest to the viewer is found. A ray is then followed from that point to the light source and Lambert's Law is applied to determine the shading at that point. The spheres now look 3-dimensional but there are no shadows.

Diffuse Light, Shadows on the Back Plane

For each pixel to be colored, a ray is followed to the viewer. If the ray intersects a sphere, proceed as above. If there is no intersection on the way to the viewer, follow a ray from the pixel to the light source. If that ray intersects a sphere, the pixel is in shadow and should be colored appropriately.

Diffuse light, Shadows on the Back Plane and Spheres

For each pixel to be colored, a ray is followed to the viewer. If there is no intersection on the way to the viewer, proceed as above. If the ray to the viewer intersects a sphere, follow a new ray from the nearest point of intersection to the light source. If this ray intersects another sphere, the point is in shadow; if not use Lambert's law as above.

Same scene and view point as above with
Light Source = (240, 600, 2000)

Spheres in Space

The entire image area was set to black. For the starry image, random white dots were added. In the ray tracing, unobstructed pixels were left unchanged. The back plane is actually transparent. The gray sphere lies mostly behind the plane.