Rendering Techniques Assignment 2:

Writing a Recursive Ray Tracer

Assigned: Monday, October 11, 1999
Due: Wednesday, October 20, 1999 (before the start of class)


For this assignment, you will extend your ray casting program to perform recursive ray tracing. In addition to performing local illumination of spheres, the program will spawn reflection and transmission rays at each ray/sphere intersection. These rays gather new illumination information about the scene and the results are combined with the local illumination to produce the final color that the ray returns.

You may find it useful to review Foley, van Dam, Feiner, and Hughes, section 16.5.2 as well as the introductory section of 16.12.

Program Description

Like the ray casting program, your ray tracing program will read a scene description from an input file and produce a PPM-format image file as output. This new program should be invoked by the following command:
raytrace <scene description filename> <image output filename>
The MAX_BOUNCES parameter in the input file specifies the maximum level of recursion for your ray tracer. If this parameter is set to zero, your program should function as a ray caster. Otherwise, your shading calculations will now call the ray tracing routine recursively for a reflection ray and a transmission ray. Each of these rays returns a color to be combined with the local illumination to determine the color returned by the current ray. The specular coefficient and color of the current surface indicate how much of the reflection ray's color may be returned by the current ray, and similarly for the transmission ray. The direction of the reflection ray is just the incident ray mirrored about the normal. The direction for the transmission ray may be computed as described in FVD 16.5.2. In the case of a total internal reflection, simply have the transmission ray return no light.

Recall that the index of refraction determines how much the light is bent during transmission.  Assume the index of refraction for the empty space (“air”) is 1.0.  Assume that the spheres are solid (not hollow).  Further assume that transparent primitives do not intersect each other (i.e. contain one another or otherwise overlap). That would require a more complex algorithm for determining the index of refraction of the current material.  Assume that light along the shadow rays is not refracted, but attenuates (filters) the color of the light in a frequency-dependent fashion according to the transmission coefficients and colors of the spheres between the surface and the light source.

A few interesting points to consider. Notice that our index of refraction model is not frequency dependent (all light is bent the same way). Also, our method of filtering the light refracted through the spheres is perhaps more surface-like than solid-like. For light to pass through a sphere, it follows along two transmission rays (e.g. rays T2 and T1 in Figure 16.54 in FVD). Each of these rays is filtered by the object's transmission coefficient and color. Thus the light has actually been filtered twice to pass through a single object. Do not attempt to correct this - simply implement it in the straightforward fashion described in FVD. The Watt/Watt description of transmission rays seems a bit different from FVD. In Watt/Watt, T1 and T2 are considered a single transmission. This avoids the previous anomaly, but it also differs in that it leaves out the local illumination and reflection ray at the junction where the ray exits the surface. It's not clear that either of these methods is more correct, so implement your recursion as described in FVD.

For your reference, a few other indices of refraction:

Water 1.33
Glass  1.52
Dense glass 1.66

As with the first assignment, this assignment includes a sample scene description and the corresponding rendered image. Like the previous sample scene, this sample provides only one small test of your program's functionality. You should test your program on this file as well as many other test cases you devise to ensure that your program functions properly in all tricky circumstances.


E-mail me a single .zip file (uuencode the file or do mime attachment) containing the following: Again, please follow the above procedure to turn in the assignment to avoid delayed grading or reduced grades.

Scene Description Format (extension .rt2)

Numbers in angle brackets are real numbers, in square brackets are integers
Naturally, the brackets do not appear in the actual file (but the colons do).
Blank lines and white space should be ignored
Lines with a ‘#’ as the first character are comments and should be ignored.
Colors should be specified in the range [0.0, 1.0]
Angles should be in degrees, and refer to the full angle (as opposed to the half angle)
# comment lines start with # and may appear anywhere
RESOLUTION: [x resolution] [y resolution]
FIELD_OF_VIEW: <full x field-of-view>
BACKGROUND: <red> <green> <blue>
MAX_BOUNCES: [maximum recursion level]
NUM_LIGHTS: [number of lights]
 POSITION: <x> <y> <z>
 DIRECTION: <x> <y> <z>
 INTENSITY: <red> <green> <blue>
 EXPONENT: <exponent>
 CUTOFF: <angle>
#in other words, one LIGHT…ENDLIGHT block for each light
NUM_SPHERES: <number of spheres>
#similarly, one SPHERE…ENDSPHERE block for each sphere
 CENTER: <x> <y> <z>
 RADIUS: <radius>
 DIFFUSE_COLOR: <red> <green> <blue>
 SPECULAR_COLOR: <red> <green> <blue>
 TRANSMISSION_COLOR: <red> <green> <blue>
 REFRACTION_INDEX: <index of refraction>

As I described in class, one way you can implement some pretty simple parsing is as follows. Open the file with fopen(). Write a simple procedure to get each line of input. This procedure can include a loop using fgets() to read a line and then test to see if it's all blank or a comment. Return the first non-blank, non-comment line. Use sscanf() to get the useful data out of the input line. sscanf() works in the presence of white space and allows you to check that the expected number of tokens were read. Of course you are free to continue using whatever method of parsing you used in the original assignment assuming that it works and allows the program to be executed with the specified command line.

Final Words of Encouragement

The good news is that this program should be significantly easier than the first assignment if your current program is well-structured. Of course, you are responsible for ensuring that your current program functions correctly as a ray caster as per my grading comments on your first assignment.

October 11, 1999