COS 526: Advanced
Computer Graphics
Fall 2008

General | Syllabus | Assignments

Assignment 3: Path Tracer (due Thursday December 4)

For this assignment, you will implement a Monte Carlo path tracer. For an overview, see course notes for 11/11 and 11/13.


Your program must do the following:
  1. Randomly generate multiple primary rays for each pixel.
  2. Trace the rays into the scene (see CS 426 notes for details).
  3. Terminate tracing paths with Russian roulette (see [Arvo 90]).
  4. At each intersection, generate two secondary rays: one to estimate the direct illumination (i.e., a ray to a light source), and one to estimate indirect (specular and diffuse) illumination. The latter ray should be generated using importance sampling [Lafortune94] according to a Lambertian + Phong BRDF. Be careful to weight these terms correctly when combining them.

Starter Code

You may begin with any ray tracing code you may have or can find. One simple option is to use the started code provided in this zip file. This code is an extended version of the code provided for the ray tracer in COS426. As before, it has packages for basic geometric primitives (points, rays, planes, triangles, etc.). However, there is a new package, called R3Graphics, that contains code to represent scenes with many types of shapes (cubes, spheres, triangles), material properties (brdfs, textures), cameras and viewports, etc. In particular, it contains code to read a scene from a .ray file, intersect rays with many types of primitives, etc.

There are two example programs provided that make a good starting point for this assignment (apps/rayviewer and apps/raytracer). The first provides an interactive viewer for rays eminating from a camera and intersecting primitives read from a .ray file. The second provides a framework for an off-line path tracing program -- it reads a .ray file and writes an image file.

The starter code provides a function (R3ReadRayFile in R3Graphics/R3Io.C) to read scene files described in .ray format. The syntax of the .ray file format is described here. Those of you who took CS426 will recognize it as a subset of the .ray file format used for the ray tracing assignment (with a few minor changes).  Most significantly, groups with arbitrary transformations are not included, which makes intersection and sampling of rays much simpler. A repository of sample .ray files is provided here.

The starter code also provides a class to read, create, and write images. By default, the class supports reading and writing files in .bmp and .ppm formats. It also can support .jpg format, with the help of the jpeg library provided at If you wish to work with jpeg files (they are smaller), download the jpeg distribution tar file, compile the for your platform, put the include file and lib file in a place that the R2Images class can find them (i.e., jpeglib.h should be placed in pkgs/jpeg and libjpeg.a should be placed in lib/), and then comment out the "#define OMIT_JPEG" directive in R2Shapes/R2Images.C. Of course, this is not required.


It is recommended that you develop incrementally (implement in small steps, and test each step separately) and that you do most of your testing on simple, well-designed examples (simple scenes, small images, few paths per pixel, stresses feature of interest, etc.) because execution/debugging times will be quite long otherwise.

The trickiest part of the assignment is to get the importance sampling right. Perhaps the notes by Jason Lawrence, a student in the Fall 2002 class, will help.