CMSC 435/634: Introduction to Computer Graphics

Assignment 6
More Ray Tracing
Due December 5, 2012

The Assignment

For this assignment, you will add specular lighting, reflection and shadows to the ray tracer from assignment 2. You can use your own ray tracer or my sample code (in ~olano/public/trace). Your new lighting computations will consists of two parts, the local surface shading, including diffuse and Blinn-Phong specular components, and limited global effects through secondary rays for shadows and reflection.

You will need to use additional parameters from the 'f' lines in the nff file. The full set of 'f' parameters is

f r g b Kd Ks e Kt ir

Where r,g,b is the base diffuse surface color, kd is the diffuse coefficient, ks is the coefficient for both reflection rays and a Blinn-Phong glossy specular component with exponent e, kt is the coefficient for refracted rays, and ir is the index of refraction.

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

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

In addition, if Ks>0, you should spawn a reflection ray, and combine the result with the local color:

totalColor = localColor + Ks*reflection

This is a recursive process, since the color of each reflection is the totalColor of whatever it hits. To avoid infinite recursion, limit the ray tree depth if the total contribution to the final color would be less than 1/255 or if the number of bounces would be greater than 5.

634 only

Add refraction if Kt>0. Limit the combined reflection and refraction ray tree depth to 5, and also stop if the total contribution to the final color is less than 1/255. If your ray tracer supports both spheres and polygons, the mount example is a good refraction test. If you only support spheres, you should also create and submit a sample NFF file including a combination of opaque and transparent spheres demonstrating your refraction.

Extra credit

There are up to 30 points of extra credit available by completing one or more of the following options. You can only receive extra credit points if you turn your assignment in on time or claim your "free late" by email before the original deadline.

For up to 5 points, scale the reflected and specular colors by the unpolarized Fresnel reflectance, assuming Ks is the reflectance at normal incidence. Scale the diffuse color by 1-Fresnel. This simulates a surface with a glossy coating, where some light is reflected, and the rest goes through the coating to interact with the surface below.

For up to 10 points, add depth of field with a jittered grid of samples in a square aperture on the lens plane. Add a command line option '-d w n', where w is a floating point aperture width and n is an integer, setting the number of samples to an nxn jittered grid. The focus plane should pass through the 'at' point specified in the NFF file.

For up to 15 points, add antialiasing with a jittered grid of samples. You can get up to 5 points if you use uniform weighting for samples within half a pixel of the pixel center, that is a uniform 1x1 pixel weighting. You can get up to to 10 points if you use a Gaussian weighting of exp(-2*r2) within 1.5 pixels of the pixel center, where r is the distance of each sample from the center of the pixel. This is a truncated Gaussian weighting with a 0.5 pixel standard deviation over a 3x3 pixel neighborhood. To conserve total energy, you will need to divide the weighted samples by the sum of the weights. Finally, you can get up to 15 points if you do the Gaussian sampling, but reuse samples between adjacent pixels. For all of the antialiasing extra credit options, you should have a command line option '-a n', where n is an integer setting the number of samples to an nxn jittered grid.

If you attempt the antialiasing extra credit, I recommend first doing the 5-point version, then extending that to the 10-point version, then the 15-point version.

Sample Images

Here are some sample images of the output with reflection and transparency (634 base assignment, no extra credit, but with all of the primitive types). 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 assn6 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.