Programming Assignment 4: Ray Tracing
Due Monday December 11 at 11:59pm

Write a ray tracer that implements at least the following capabilities: The corresponding lighting model equations in the textbook are:
(10-2)  radial attenuation
(10-5) angular attenuation
(10-9) for diffuse reflection
(10-13) for specular reflection
(10-19) for combined lighting  

Quadric Surfaces

In this assignment, your ray tracer will only need to support quadric surfaces of the form:

F(x,y,z) = Ax2 + 2Bxy + 2Cxz + 2Dx + Ey2 + 2Fyz + 2Gy + Hz2 + 2Iz + J = 0

This general equation can be written in matrix notation as xTQx = 0, where Q is the 4x4 matrix:

Q = | A B C D |
       | B E F G |
       | C F H I  |
       | D G I J   |


and xT = [x y z 1].

To intersect a ray x= p + tu with the quadric surface, we simply substitute x into the matrix equation above. Expanding out we get

0 = xTQx = (p + tu)TQ(p + tu) = (uTQu)t2+ (2uTQp)t + (pTQp)

which is a quadratic equation in t.  

A vector in the direction of the normal to the surface at any point x on the surface is simply n = Qx.

Objects Composed of Multiple Surfaces

In your implementation, solid objects should be defined in terms of a collection of surfaces of the form xTQx = 0.  Each surface's implicit equation defines two half-spaces: any point x is inside if xTQx ≤ 0, or outside if xTQx > 0.  Thus, a convex solid object can be defined as the union of all the inside half-spaces for a collection of surfaces.  For instance, a box can be defined in terms of inside half-spaces of 6 planes.  A cylinder can be defined in terms of one cylindrical surface, and two planes that define its end caps.

Ray Tracer Model Files

Model files for testing the ray tracer, and a model file pre-viewer are provided.  As part of your assignment grade, you are required to read models from these files and render them with your ray tracer:

model1.dat
model2.dat
model3.dat

The model files adhere to the format described here.  You should use this model file format for any additional models you create for this assignment.  You are welcome to extend the file format as you see fit.

Simpler Test Case: Spheres with Shadows/Reflections

If you are unable to implement cylinders and boxes, we recommend that you demonstrate your ray tracer using a simpler model (spheres only). Here is an example, with shadows and reflections enabled.

sphereTest.dat

In the event that your ray tracer cannot handle boxes and cylinders, then submit an image for this instead of for "model2.dat." Also, please be prepared to show the resulting image at your demo. Here's what a correct rendering looks like:

Model Preview Tool

Source code for a OpenGL model file preview tool for Linux is provided here.
Source code for the .NET environment for the preview tool is provided here.

Image File Output

You are welcome to submit the images produced by your ray tracer in GIF, TIFF, JPEG, or PPM format.  

A function for writing PPM image files is provided here.

Extra Credit

For extra credit, implement as many of the following as you like:
  1. CSG (20 points -- required for CS680 students) 
  2. texture mapping  + bump mapping (10 points total)
  3. transmission with refraction (10 points total)
Graduate students are required to complete CSG, but can do more for extra credit (ten points extra credit each).

Demo

Part of your grade for this programming assignment will be based on your giving a short demo (5 minutes) in the CS cluster. You show your images, and demonstrate your program working on at least one model .dat file. Demos will be held on Wednesday and Thursday after the due date, during the scheduled section meetings. You will be asked to sign up for a demo slot in class.

Source Code Submission

Submit five (5) different images generated by your ray tracer.  Of these, 3 should show the results for the test model files provided with this assignment: model1, model2, and model3. The other 2 images should each depict a different scene model and viewpoint. Submit your model files for these scenes. These two additional model files must demonstrate the full capabilities of your ray tracer.  For instance, if your ray tracer supports spheres, cylinders, ellipsoids, boxes, transmission, reflection, shadows, texture+bump mapping, then EACH of these additional images should demonstrate ALL of these capabilities. Your program source files, Makefile, and five output images are to be submitted electronically. Use the submit program on the CS cluster. 

Helpful Hints

Note that a 3D vector in its homogeneous representation will have w=0. For example, the vector that points from (a,b,c,1) to (d,e,f,1) = (d-a,e-b,f-c,0).

Grading (Out of 100 points)

Spheres and ellipsoids, using xTQx ray/surface intersction solver 20 points
Boxes and cylinders, using collections of surfaces and  xTQx solver 20 points
Correct implementation and demonstration of lighting model and colored lights in the five images submitted:
  • point lighting  (4 points)
  • spot lighting -- angular attenuation (4 points)
  • ambient lighting (4 point)
  • infinite source (4 points)
  • proper specular reflection (4 points)
  • proper diffuse reflection (4 points)
24 points total
Shadows 18 points
Reflection
18 points
(20 points -- required for CS680) CSG
(10 points) texture + bump mapping
(10 points) transmission and refraction
Extras

Late Assignment Policy

Late programming projects and problem sets will be levied a late penalty of 10% per day (up to three days). After three days, no credit will be given.

Collaboration/Academic Honesty

All course participants must adhere to the CAS Academic Conduct Code. All instances of academic dishonesty will be reported to the academic conduct committee.

Stan Sclaroff

Created: November 21, 2005. Revised: November 16, 2006.