15-462 Programming Lab 3: Ray Tracer

Due Tuesday, April 10th, 11:59:59 PM

An Overview

For this project you will implement a ray tracer. Besides the basic scene file parser, you will have to implement everything on your own. We suggest using the libgfx libraries for the mathematical functions that you will need. One way to write pixels to the screen buffer is to first create a large enough buffer in memory, write to it as you perform raytracing, then create a texture map (GL_TEXTURE_RECTANGLE_NV) and fill it by glTexImage2D, then render it to screen or save it to a file.

Scene Format

You can create your own scenes to show off the raytracer in action; however, you will have to implement a simple command-line interface and support a common scene format so that we can test your code. The code to parse the Simple Scene Description Format is provided for you (rt_parse.h/cpp). A simple example can be found here.

Simple Scene Description

The (informal) grammar for the simple scene description format is as follows:

Symbol Key:
scene :: = background lights materials group

background ::= Background {
  color Vec3f
  ambientLight Vec3f

lights ::= Lights { 
  light *

light ::= Light {
  position Vec3f
  color Vec3f
  ( attenuation float float float ) ?

camera ::= Camera {
  eye Vec3f
  center Vec3f
  up Vec3f
  fovy float

materials ::= Materials {
  material *

material ::= Material {
  textureFilename string
  diffuseColor Vec3f
  specularColor Vec3f
  shininess float
  ( transparentColor Vec3f )?
  ( reflectiveColor Vec3f )?
  ( indexOfRefraction float )?

group ::= Group {
  object *

object ::= sphere | triangle | trimesh

sphere ::= Sphere {
  materialIndex int
  center Vec3f
  radius float

triangle ::= Triangle {

  vertex0 Vec3f
  normal_vertex0 Vec3f
  materialIndex0 int
  s_t_tex_0 float float

  vertex1 Vec3f
  normal_vertex1 Vec3f
  materialIndex1 int
  s_t_tex_1 float float

  vertex2 Vec3f
  normal_vertex2 Vec3f
  materialIndex2 int
  s_t_tex_2 float float


trimesh ::= TriMesh {
  objfile file.obj
  materialIndex int

Vec3f ::= float float float

Light attenuation

We will use an inverse quadratic attenuation model for the lights in the scene. Intensity at a distance d from the camera is defined as
I(d) = 1
ad2 + bd + c

Spherical Coordinates for Texturing

For texturing your spheres, use the spherical coordinate definition given by Mathworld. Just use longitude as the s texture coordinate and latitude as the t texture coordinate. Here is a source of nice textures which are already in a lat/lon parameterization.

Command line Parameters

Required Features [100 points]

Your first step should be to create a backbuffer and setup OpenGL to display it. All other code you write will directly modify this buffer. You must implement the following features:

Ideas for Extra Credit Features [up to 20 points]

Here are some suggestions for extra credit ideas.


You can find the lab 3 starter code here. The submission guidelines remain the same as the previous labs. Make sure your project can be compiled by just going into the src directory and typing make.

Please include a copy of whatever models and textures you use when handing in your project as it makes life a lot easier to verify your features.