CMSC 435/634: Introduction to Computer Graphics

Assignment 5
Due April 30, 2008

The Assignment

For this assignment, you will add lighting computations to your ray tracer from assignment 4. Working ray tracing code is available on request. Your new lighting computations will consists of two parts, the local surface shading, including diffuse and Phong-specular components, and limited global effects through secondary rays for shadows, reflection and refraction. You will need to use the 'l' light position and color lines from the NFF file, as well as the remaining parameters from the 'f' object material lines. For the basic assignment, you need only shade polygons using the polygon normal. Shading of other primitives or polygons with per--vertex normals is extra credit.

For each intersection, you will shoot shadow rays toward each light to determine if the light is visible from the intersection point. Visible lights should contribute:

localColor.r = lightColor.r * (Kd*surfaceColor.r*diffuse + Ks*specular)
localColor.g = lightColor.g * (Kd*surfaceColor.g*diffuse + Ks*specular)
localColor.b = lightColor.b * (Kd*surfaceColor.b*diffuse + Ks*specular)

In addition, if Ks>0, you should spawn a reflection ray, and if T>0, you should spawn a refraction ray, resulting in a total color:

totalColor = localColor + Ks*reflection + T*refraction

This is a recursive process, since the color of each reflection and refraction ray is the totalColor of whatever they hit. To avoid infininite recursion, limit the ray tree depth (i.e. number of bounces) to 5. You may skip the reflection or refraction ray if the contribution to the final color would be less than 1/255, but that optimization is not necessary.

Extra credit

There are a variety of extra credit options to add normals and shading computations for different primitive types: shading of spheres (5 pts), shading of cones (15 pts), and either interpolated normals for triangular 'pp' polygon primitives (5 pts) or interpolated normals for convex 'pp' primitives (10 pts). You can also modulate the reflected and refracted ray contribution by the Schlick approximation to the Fresnel reflectance equations for unpolarized light (5 pts).

634 only

Add any physically plausible specular BRDF as an alternative to the Phong model. You should add a new surface specification line using any unused letter code to specify the parameters needed for your model. You should be able to have objects with both Phong and BRDF models in the same scene. Say you chose 'x' — each new 'x' or 'f' line should override any previous 'x' or 'f'. In other words, primitives given after an 'f' line should use the Phong model, and primitives after an 'x' line should use your chosen BRDF. Include at least one sample NFF file demonstrating your extension.

Sample Images

Here are some sample images of the output. Counts are given in terms of numbers of polygons (p), polygons with per-vertex normals (pp), spheres (s) and cylinders/cones (c)

-s 1 -s 2 -s 4 default
balls 1 p, 10 s 1 p, 91 s 1 p, 7381 s same as -s 4
gears 147 p 1169 p 9345 p same as -s 4
jacks 6 s, 3 c 54 s, 27 c 3510 s, 1755 c same as -s 1
lattice 8 s, 12 c 27 s, 54 c 125 s, 300 c 2197 s, 6084 c
mount 8 p, 4 s 32 p, 4 s 512 p, 4 s 8192 p, 4 s
rings 1 p, 30 s, 30 c 1 p, 150 s, 150 c 1 p, 900 s, 900 c 1 p, 4200 s, 4200 c
sample 16 p, 864 pp, 1 c same as -s 1 same as -s 1 same as -s 1
shells 361 s 721 s 2881 s 5761 s
sombrero 1922 p 7938 p 130050 p same as -s 1
teapot 1 p, 56 pp 4 p, 240 pp 16 p, 992 pp 36 p, 2256 pp
tetra 4 p 16 p 256 p 4096 p
tree 1 p, 3 s, 3 c 1 p, 7 s, 7 c 1 p, 31 s, 31 c 1 p, 4095 s, 4095 c

What to turn in

Turn in this assignment electronically by checking your source code into your Assn5 CVS directory by 11:59 PM on the day of the deadline. As always, double check that you have submitted everything we need to build and run your submission. Be sure to include a Makefile that will build your project when we run 'make', and a readme.txt file telling us about your assignment. Do not forget to tell us what (if any) help did you receive from books, web sites or people other than the instructor and TA, what (if any) extra credit features you added, and (if 634) about your BRDF, NFF extension, and test file.