Project 4

CSE 167: Computer Graphics


Project 4: For project 4, make a basic ray tracer that renders a Model with diffuse lighting and shadows.


Project 4 is due before 3:30 pm, December 5, 2005

Project 4 is worth 15 points. The updated point breakdown is:


3: Generate eye rays for each pixel.

2: Triangle and Model ray intersections.

2: Barycentric normal and color interpolation for triangles.

3: Basic lighting

3: Shadows

2: Good object oriented design


+1: Mirror reflections

+1: Glassy refraction (& Fresnel)

+1: Antialiasing

Ray Tracer

The goal is to make a simple ray tracer that generates an image of a ‘Model’ with basic diffuse lighting and ray traced shadows. Only primary eye rays and shadow rays need to be implemented (reflections & refractions are optional).


This can be achieved by starting with ‘Ray’ and ‘Intersection’ data structures as shown in lecture 16. Also, I’d suggest a Triangle::IntersectRay() routine as well as a Model::IntersectRay() routine that just loops through and tests all of the triangles. Remember to check the distance of the intersection point along the ray to make sure it returns the closest intersection.


From there, I’d make a function in the Camera class that generates an image by looping through all of the pixels and generates a primary ray for each pixel. If that ray hits a surface, trace a ray from there to each light and determine if the light is visible. If it is, use a simple dot product based diffuse lighting equation to computer the lighting. The Camera can store the image as an array of pixels and have a function that displays the image.


You may also want to try to integrate the ray tracing with the interactive GL viewing, so that you can position the camera with GL and then press a key to generate a ray traced image. This is not required, however.


Please take a look at the book, as it has a chapter on ray tracing and another one on ray-object intersections. There is also some sample code with the book and previous classes that you may look at for ‘inspiration’ only.


Base Code

You can download the basecode for project 4 here:


The zip file contains multiple header and source files. You will need to create a project in your IDE and add these files to it. The base code renders a multi-colored cube on a flat ground plane using OpenGL. By hitting 'r' you will enter ray tracing mode. This will call the code YOU need to implement, so currently the resulting image is just black. Once the image has been rendered you can press 'p' to save a picture in PPM format. Once you have completed the assignment your resulting ray traced image should look something like this:



Please take the time to get familiar with the code. The code is clearly marked with TODO comments in functions you need to implement.


Importing the files into a new Visual Studio .NET project may result in a couple compiler errors related to the "exit" function. To fix this, right click on the project name in the Solution Explorer tab and select Properties -> C/C++ -> Preprocessor. Make sure that the active configuration is set to all, and then in the Preprocessor definitions line append GLUT_BUILDING_LIB.