Department of Computer Science
Worcester Polytechnic Institute

CS-4731: Computer Graphics
Assignment 4
Due: December 11, 2006 at 11:59pm

Objective: In this assignment, you will add the lighting calculations to a basic ray tracer. The funcionality needed to load and render a scene in OpenGL will be given to you, as well as the routines for computing the intersections between eye rays and simple shapes (flat polygons, spheres, etc.). You will need to compute the proper lighting for the objects in the scene. As in previous assignments, this assignment consists of two parts: a "Preparation" part and a "New Stuff" part.

Preparation: For this project, you are provided with code for a Basic Ray Tracer (BRT), as well as some sample scene description files. Get and compile the BRT code base which is provided in tar format. Makefiles for the Unix, Mac OSX, and MinGW environments have been included in the BRT tar file. Compile the BRT code base and try to run it. To specify a scene file that is different from the default "ball.dat" file, use the "-s" command-line option. So, to load the scene file called "foo.dat", you would type "./BRT -sfoo.dat". The command "./BRT -?" can be used to print a usage message.

Once you have compiled the code, running it will display a window with the scene. By default, the program will render the given scene using OpenGL. You can use the keyboard commands to control the camera movement. By pressing the 'x' key, you can tell the program to render using your ray tracing code. With no changes to the code, the display shows something like this (click for larger images):


OpenGL rendering

Initial ray-traced rendering


New Stuff:

Starting with the main() routine in the file BRT.cpp, walk through the code, and convince yourself you understand what is going on at each step. There are a number of classes that are called upon in this assignment, and though you might not be modifying many of them, it is important that you understand what they are doing. You should pay special attention to the Camera, GeomObj, Ray, Shape, and Scene classes.

In the file Scene.cpp, you will find a routine called Color3 Scene::shade( Ray& ray ). This is the function where you will be doing most of your work. There are comments describing what and where you need to add.

Specific Requirements:

  1. Add the code to implement ambient lighting.
  2. Add the code to implement diffuse lighting.
  3. Add the code to implement specular lighting.

Extra Credit: The extra credit for this assignment allows you to produce more "realistic" images.

  1. Reflections: Add the computations to your shade function to follow reflection rays. There is a value maxRecursionDepth in the Scene class (and in the scene data files) that determines how many times your ray tracer should trace reflection rays. You should have all the information to determine the reflection ray, etc. at your hit point. Follow the reflection rays to the designated depth and accumulate the colors.
  2. Shadows: Add the computations to your shade function to compute whether the hit point is in shadow, and alter the color accordingly. You need to do this for all the lights in the scene.

Documentation: You must create adequate documentation, both internal and external, along with your assignment. The best way to produce internal documentation is by including inline comments. The preferred way to do this is to write the comments as you code. Get in the habit of writing comments as you type in your code. A good rule of thumb is that all code that does something non-trivial should have comments describing what you are doing. This is as much for others who might have to maintain your code, as for you (imagine you have to go back and maintain code you have not looked at for six months -- this WILL happen to you in the future!).

I use these file and function (method) headers, in my code. Please adopt these (or the official CS ones) for all your assignments. The file header should be used for both ".h" and ".c" (or ".cpp") files.

Create external documentation for your program and submit it along with the project. The documentation does not have to be unnecessarily long, but should explain briefly what each part of your program does, and how your filenames tie in. Most importantly, tell the TA how to compile and run your program.


What to
Turn in:
Submit everything you need to compile and run your program (source files, data files, etc.)

BEFORE YOU SUBMIT YOUR ASSIGNMENT, put everything in one directory on ccc.wpi.edu, compile it, and make sure it runs. Then tar everything up into a single archive file.

The command to tar everything, assuming your code is in a directory "ass4", is:

tar cvf FirstName_LastName_ass4.tar ass4

To submit your work, you will use the turnin utility on CCC. Here is a link to instructions about how to do this. The turnin ID is: "hw4", so to submit your work, you would type something like this when logged in to the CCC machine:

/cs/bin/turnin submit cs4731 hw4 FirstName_LastName_ass4.tar


Academic
Honesty:
Remember the policy on Academic Honesty: You may discuss the assignment with others, but you are to do your own work. The official WPI statement for Academic Honesty can be accessed HERE.


Back to course page.