15-462 Computer Graphics I
Assignment 7 - Ray Tracing
150 points

Overview

In this assignment, you will be building a ray tracer. Your ray tracer will be able to handle opaque surfaces with lighting, shadows, reflections and texture mapping. Provided for you will be starter code that will load scene data from a file.

The first step is to uniformly send out rays from the camera location. We suggest you use backwards ray tracing where rays are sent from the camera, one ray per pixel. We would recommend the final images be 640x480, but for debugging you would see faster rendering times for fewer rays. For example, if you halve each dimension, you would send out 1/4th of the number of rays.

There are a number of ways to store the data generated from ray tracing. One way is to directly output each pixel to the screen as it's generated. If you do a flush and swap buffers, you can watch the scene being rendered. The disadvantage is that this may be a slow way to render; a speed up may be to write the data to the display every line, instead of every pixel. Another way to render is to store the data in an off-screen buffer, and send the whole data to the video buffer. This may be faster, as accessing the video buffer directly may be slow. To write to the video buffer, you should use the function glWritePixels. The PIC_PIXELS macro can be used for jpeg writing. You could use the PIC_PIXELS macro to not deal with the OpenGL at all. Just allocate memory for a jpeg file, and use the PIC_PIXELS macro.

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

The third step is to implement the illumination equations. The suggested illumination equation is provided below.

The final step is to implement extra features. You may pick features that interest you from a provided list.

Intersection Testing

For intersection testing, the lecture notes and handout provide you with the equations.

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

You will also need to implement texture mapping. For triangles, this is very similar to interpolating normals. For spheres, we suggest using spherical coordinates for texture mapping.

Illumination

We suggest using a slightly modified version of the formula provided on page 252 of your textbook. The slight modifications are as follows:

  • Ld = Ls = color of the light (the diffuse and specular components of the light are the same as its color).
  • A global La (global light ambient term).
  • ka = kd (the ambient material term is the same as the diffuse material term).

Functionality Requirements

This is the list of requirements for this assignment.

  • Triangle Intersection (20 points)
  • Sphere Intersection (20 points)
  • Triangle texture mapping (20 points)
  • Sphere texture mapping (20 points)
  • Triangle Phong shading (10 points)
  • Sphere Phong shading (10 points)
  • Shadows rays (20 points)
  • Animation or Still (10 points)
  • Recursive reflection (5 points)

The above list constitutes 135 points of the 150 point assignment. For the other 15 points, and up to 30 points possible extra credit, you may choose features to implement from the following list.

  • Recursive refraction (10 points)
  • Good antialiasing (15 points)
  • Motion blur (15 points)
  • Spatial partition: octrees or BSP trees (45 points)
  • Blin Blobs (45 points)
  • Soft Shadows (20 points)
  • Bounding Box or Sphere optimization (15 points)
  • One or two additional types of objects in scene (10 points/class)

Scene Description Format

The first line is the number of objects in the file. There are three types of objects supported: lights, triangles, and spheres. Color values range from 0-1.

The format is as follows:
Number of Objects (1 integer)
Ambient Light (3 floats).
Then you can have lights, spheres or triangles.

  • sphere
    • texture name (up to 40 chars, or null)
    • position (3 floats)
    • diffuse color (3 floats)
    • specular color (3 floats)
    • shininess (1 float)
    • radius (1 float)
  • triangle
    • texture name (or null)
    • then 3 of the following
      • position (3 floats)
      • diffuse color (3 floats)
      • specular color (3 floats)
      • normal (3 floats)
      • shininess (1 float)
      • s,t texture coordinates (2 floats)
  • light
    • position (3 floats)
    • color (3 floats)

Following is an example of a scene description file. It sets a gray sphere of radius 1 at (0,0,-3), with no texture. It sets a white light source at the origin.

		  2
		  .3 .3 .3
		  sphere
		  null
		  0.0 0.0 -3.0
		  .3 .3 .3
		  .5 .5 .5
		  1
		  1
		  light
		  0 0 0
		  1 1 1

Animation or Still

In addition to your program, you are also required to hand in an animation or still picture in the form of JPEG file(s). See the sample code jpegwrite.c from Assignment 3 for how to write such these files.

  • The animation or still should be something which shows off your features.
  • For example, if you implemented a spatial partition, your scene could be more complicated. If you implement recursions, you should show them off.
  • The animation should consists of a series of JPEGs stored in a subdirectory called movie/.
  • If you do a still, please create a directory called movie/ and put a few seconds worth of copies of the still. We run at 15 frames/second.
  • The JPEGs should be numbered consecutively starting from 000.jpg.

Grading

Grading is based on functionality of your ray tracer. You may get up to 30 points of extra credit.

Handin Instructions

In your graphics handin directory, /afs/andrew/scs/cs/15-462/students/user/, create a subdirectory called asst7/. In that directory submit all your files (source code, Makefiles, texture maps, scene descriptions, ...). MAKE SURE YOU INCLUDE A MAKEFILE.

Include a readme file that describes the functionality of your ray tracer. In the readme, list your scene description file(s) that show off your features.

In a subdirectory called movie/ copy all your JPEGs into it. Number them consecutively starting from 000.jpg.

Starter Code

The starter code takes a file at the prompt which contains a scene description. It fills global structures containing triangles, spheres, and lights.

As usual, you are free to use any language you like, but we will only actively support C and C++, and we will require that your code compile and run in the graphics cluster.

Tips

  • Start soon, this is a difficult assignment.

Links


[ Home | Schedule | Assignments | Software | Resources ]

fp@cs
Frank Pfenning