15-462 Programming Lab 3: Ray Tracing

Due Tuesday, November 13th, 11:59 PM


An Overview

In this assignment, you will be building a ray tracer. As already discussed in lecture, ray tracing is a powerful method to perform global illumination. Ray tracers are widely used to render photorealistic images and animations. You can try the interactive ray tracer [8] to see how the ray tracer works step by step. Examples of globally illuminated renders of a Cornell Box (some ray traced) can be found at Henrik Wann Jensen's page at [6]. Also, you might want to take a look at the Internet Ray Tracing Competition for inspiration [7]. Other useful materials on ray tracing are in the links section at the end of this handout.

At the end of this assignment, your ray tracer should be able to minimally handle opaque surfaces with lighting, shadows, reflections and texture mapping. Provided for you will be some starter code that performs some elementary parsing functions.

Sending out rays

The first step is to uniformly send out rays from the camera location. You will need to use backwards ray tracing where rays are sent from the camera, one ray per pixel. For your project submission, the image size must be 640x480. In the starter code, the width and the height have been reduced to help you debug more quickly. Your code shoulde work on any dimension.

When generating your scene, use a perspective projection "camera" with the camera properties specified by the input scene file. This will allow us to standardize images for testing.

Intersection Testing

The next step would be to write code for intersections and texture mapping. The mathematical solutions for the intersection and texture mapping code are provided in the lecture notes and handouts.

In order to perform Phong shading, normals are required. For triangles, you can interpolate the x, y, and z coordinates of the normals at each vertex, and then normalize the length. We recommend using barycentric coordinates for interpolation of triangles. For spheres, the normal is simple to calculate from the center of the sphere.

You are also required to implement texture mapping. For triangles, this is very similar to interpolating normals. For spheres, we recommend using spherical coordinates for texture mapping.

Illumination

The third step in the process would be to implement the illumination equations. The illumination equation for a surface point is given by:

I = (ka * Ia) + Ii * (kd * (L . N) + ks * (R . V)^n)

The slight modification we suggest you use is as follows:

ka = kd (the ambient material term is the same as the diffuse material term).

Note that in the ideal ray tracer, there should be no ambient effect. That would make the area the light cannot reach completely dark.

For materials with a non-zero specular component, you need to recurse (upto a maximum depth of at least 3). To add in the value of this recursive ray, use the following formula:

Ifinal = I + ks * Ir

Implementation

Starter Code

The starter code [1] has been set up to be able to built in both Visual Studio 2005 and with the Makefile in Linux.

You will begin by implementing CalculatePixel(int screenX, int screen) in RayTrace.h to return the correct color at that screen coordinate. The screen-coordinates start with (0, 0) at the bottom-left corner up to (WINDOW_WIDTH, WINDOW_HEIGHT) at the top-right.

The starter-code also allows you to dynamically change your position in 3D Space using the (W,A,S,D) keys and the Arrow keys and preview the scene set-up with a real-time fixed-function pipeline implementation. This should allow you to check your camera and perspective calculations against your RayTracer.

Other important files include:

Object Types

There are 3 pre-defined object types in the starter code. Your program must support ray tracing for each of these object types.

For each object type, Scene.h also defines the rigid body transformation parameters including rotation angles, scales, and translation units. These transformation allow you to create an ellipsoid and rotate model objects. Handling these parameters is an extra credit work. For the requirement submission, you can safely assume that the rotation and translation parameter will always be 0 and the scalation will always be 1.

Grading Criteria

Your program must:

Submission

Please submit your project to /afs/andrew/scs/cs/15-462/turnin/your_andrew_id/. Copy your modified src directory into that directory. When we run "make" in the src directory it should compile your program successfully. Also within asst3, make a sub-directory called scenes and images, and place your representative XML scene files and JPEG snapshots into the respectively sub-directory.

Tips

Extras

Here are some suggestions for extra credit ideas:

Other cool things will get extra credit as well (talk to the TAs before you actually implement it).

Please note that the amount of extra credit awarded will not exceed 10% of this assignment's total value.

Links

[1] Starter code
[2] Introduction to Ray Tracing, Chapter 1 (CMU IPs only)
[3] Introduction to Ray Tracing, Chapter 2 (CMU IPs only)
[4] Introduction to Ray Tracing, Chapter 6 (CMU IPs only)
[5] Ray Tracing Materials on SigGraph.org
[6] Cornell box images by Henrik Wann Jensen
[7] Internet Ray Tracing Competition
[8] Interactive Ray Tracer