CMSC 435/634: Introduction to Computer Graphics

Assignment 2
Ray Tracing II
Due February 26, 2014

The Assignment

For this assignment, you will add diffuse and Blinn-Phong specular lighting with shadows, reflection, and refraction to the ray tracer from assignment 1. You can use your own ray tracer or my sample code (in ~olano/public/trace).

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 compute a total color as the sum of Ks*reflection if Ks>0; Kt*refraction if Kt>0; and for each light, a diffuse and specular contribution if a shadow ray will hit the light.

Given unit normal, N, unit vector toward the light, L, and unit vector halfway between the light and ray, H, the diffuse and specular contribution for one light would be computed as:

diffuse = max(0, dot(N,L))
specular = pow(max(0, dot(N,H)), e)
color.r = (Kd*r + Ks*specular) * diffuse * lightColor.r
color.g = (Kd*g + Ks*specular) * diffuse * lightColor.g
color.b = (Kd*b + Ks*specular) * diffuse * lightColor.b

Computing the color is a recursive process, since the color of each reflection and refraction ray is the total color 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. The easiest way to do this is to add data to each ray to track the number of bounces left and the total contribution so far. For example, a ray that is the result of one reflection with coefficient Ks1, then one refraction with coefficient Kr2 would have three bounces left and a maximum possible contribution of Ks1*Kr2

634 only

Implement depth of field by shooting multiple rays per pixel. You should allow the user to specify the number of rays and aperture size. The focal plane should pass through the 'at' point specified in the nff file.

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, but no generated files (.o's, executables, or images). 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.