CS 371
Computer Graphics
Spring 2005


Program 2: A Better Ray Tracer

Due on 3/18/05 before MIDNIGHT

In this assignment you will be implementing a more flexible and functional recursive ray tracer. Your ray tracer should be able to read scene files written in a specified scene file format (SFF), then render the scene most recently read.

Program Requirements

Program Organization

In order to produce a flexible, extensible ray tracer, you will use the concepts discussed during the past few weeks of class. Your surfaces should be described in local (object) coordinates, and provide 4D transforms for moving back and forth betwen object and world coordinates. Your camera, similarly, should provide 4D transforms for moving between camera and world coordinates. Each surface should provide a method Hit getIntersection(Ray r) which returns a Hit object containing the t-value of the hit point, the normal to the surface at the hit point, the hit surface, and the appropriate shader to use.

Key Classes

Your system should provide the following classes:
Ray
As in previous assignment.
Light
An abstract class with at least two derived classes: PointLight and DirLight, which are point and directional light sources respectively.
Camera
Describes position and orientation of eye and viewing rectangle. Defined by parameters eye, lookAt, up, viewAngle, aspectRatio, near, far as defined in text. Supports operations for producing sample rays from eye into scene.
Shape
The geometric structure of a surface. This should be an abstract class with sub-classes for actual shapes (e.g., Sphere, Plane, etc).
Material
Contains material properties of surface.
Surface
A shape and its material properties.
Hit
Information about an intersection of a ray with a surface. Should contain enough information for determining the hit point, the hit surface, the normal to the hit surface at the hit point, the material properties for that point/surface.
Scene
Holds lists of surfaces, lights, and a camera (or list of cameras), as well as any global information such as ambient light intensity, dimensions of graphics window, and so on.
Renderer
The ray tracer. Renders a scene. Alternatively, you can make this the "main" program, and not a class.

Putting It All Together

Initialization
Rendering
For each sample ray

Help!

Provided Code and Libraries

CS371
The graphics window library from the previous assignment.
linAlg
A library providing vector and matrix calculations in 3 and 4 dimensions for both float and double types. The header files are in /usr/cs-local/include/cs371include. Read them for details.
sampleProgs
Samples of use of the above. Available in /home/faculty/lenhart/shared/cs371Fall02.
simpleShapes
An example of an abstract base class and some derived classes. You will need to modify these for your "generic" shapes.
other
Ray, Light, SceneReader and other classes from the previous assignment, as well as makefiles. Note: Systematic use of makefiles and good directory structure will be well worth the effort invested!

Enhancements and Extensions

As before, there are countless ways to have fun with this assignment. Here are some:

What to turn in

To turn in your work, create a directory containing all files necessary to make your program run (source code, header files, object code, makefiles, README file, etc). This assignment will have a number of classes, your README file shoulde include brief descriptions of the classes and their functionality, as well as features provided, outstanding issues, etc.

Call your directory yourlastnameProg21 and pack it into a single "tar" file. Then drop the tar file off in the drop-off directory. The files in your directory should be correctly set up so that I can compile and run them without having to make changes.

For more information...

Any news flashes will be added to the course home page. There are also links to the source code for the programs that we have been discussing in class. And, again, there's me.

Scene File Format

A scene file contains all information needed to render the scene. The format is similar to that of the last assignment with some differences/extensions. Surfaces get the current material properties and transform as their own. The initial material "state" should be "ambient", and the initial Transform should be the identity. Transforms are processed in the following manner: The keyword "identity" causes the current transform to be set to the identity matrix. Reading in a new transform T updates the current transform by multiplying it by T (that is, T becomse T*newT). So, to create a sphere of radius 4 centered at (2,3,-5), the scene file would contain the lines
identity
translate (2,3,-5)
scale (4,4,4)
ellipsoid
So a point p on the ellipsoid would be transformed by translate(2,3,-5)*scale(4,4,4)*p.

Below is a sample scene file, including a full description of the scene file format. If you wish to add features, you should do so in a manner consistent with this format. I have included some examples of the suggested format for optional features, such as spotlights. Such lines are commented as optional. If you end up not implementing certain features, your program should still read in the files and skip over the non-implemented features, by skipping the rest of the line describing the feature and continuing to process the file.

// Here is a sample scene. The keyword // indicates a comment that extends
// the end of the current line.
// Keywords and parameters
// The Scene-------------------------
// numX n
// 	int n is the number of items of type X to be entered, for example
// numLights n
// numSurfaces n
// windowDims (rows, cols)
//	where rows and cols are int
// sceneAmbient (ambient)
//	Point3Df ambient
// antialias n	// optional
//	int n is the number of sample rows/cols per pixel
// fast n	// optional
//	int n is the number of pixel rows/cols per sample
// Cameras-------------------------
// camera (eye,lookAt,up,viewAngle,aspectRatio,near,far)
// 	Point3Dd eye, lookAt, up
//	double viewAngle, aspectRatio, near, far 
//	Note: near and far are given as positive values:  They represent
//	distance from eye along negative n axis.  Angle is in radians
// Lighting-------------------------
// pointLight (location, diffuse, specular)
//	Point3Dd location;
//	Point3Df diffuse, specular
// dirLight (direction, diffuse, specular)
//	Point3Dd direction;
//	Point3Dfdiffuse, specular
// spotLight (location, diffues, specular, direction, angle) // optional
//	Point3Dd direction; double angle (radians)
// Materials-------------------------
// A material property applies to all surfaces after it but before the next
// material property
// matAmbient ambient
//	Point3Df ambient
// matDiffuse diffuse
//	Point3Df diffuse
// matSpecular specular
//	Point3Df specular
// matSpecExp specExp
//	double specExp
// matReflection reflection
//	double reflection (in range [0,1])
// matTransparent transparent
//	double transparent (in range [0,1])
// Shaders (optional)-------------------------
// A shader applies to all surfaces after it but before the next shader
// ambient
//	Use only ambient lighting
// lambert
//	Use only lambertian lighting
// phong
//	Use phong lighting
// phongS
//	Use phong lighting with shadows
// phongSR
//	Use phong lighting with shadows and reflection
// phongSRT
//	Use phong lighting with shadows, reflection and non-refractive
//	transparency
// phongSRF // optional
//	Use phong lighting with shadows, reflection and refractive transparency
// Transforms-------------------------
// A transform applies to all surfaces after it but before the next transform
// All rotations are counter-clockwise
// identity
// xRotate angle
// yRotate angle
// zRotate angle
// rotate (angle,direction)  // see text for description
//	double angle (radians); Point3Dd direction
// scale (xscale, yscale, zscale)
//	double xscale, yscale, zscale
// translate (xtranslate, ytranslate, ztranslate)
//	double xtranslate, ytranslate, ztranslate
// transform T // optional
//	Transform4Dd T is an arbitrary transformation
// invtransform T // optional
//	The inverse of T
// Surfaces-------------------------
// Any surface defined before the first shader/transform get
// default values: ambient shader and identity transform
// ellipsoid
// plane
// cylinder
// taperedCyl (optional)
//	double s (see text for details)
//----------------------------------
windowDims (300,300)
sceneAmbient (0.2,0.2,0.2)
numLights 2
numSurfaces 5
camera ((0,0,3),(0,0,0),(0,1,0),1,1,1,100) // note: near and far are positive
dirLight ((-1,1,4),(.6,.6,.6),(.6,.6,.6))
pointLight ((5,5,4),(.5,.5,.5),(.7,.7,.7))
matAmbient (0.19125, 0.07355, 0.0225) 
matDiffuse (0.7038, 0.27048, 0.0828)
matSpecular (0.0256777, 0.137622, 0.086014)
matSpecExp 12.8
phong
identity
translate (-1,-1,-4)
ellipsoid		// a sphere of radius 1 centered at (-1,-1,-4)
//
matAmbient (0.329412, 0.223529, 0.027451)
matDiffuse (0.780392, 0.568627, 0.113725)
matSpecular (0.992157,0.941176,0.807843)
matSpecExp 27.8974
matReflection 0.0
identity
translate (0,0,-5)
scale (2,2,2)
ellipsoid		// a sphere of radius 2 centered at (0,0,-5)
phongSR
translate (1,1,2)
ellipsoid		// a sphere of radius 2 centered at (1,1,-3) (Why?!)
//
matAmbient (0.25, 0.25, 0.25)
matDiffuse (0.4, 0.4, 0.4)
matSpecular (0.774597, 0.774597, 0.774597)
matSpecExp 76.8
matReflection 0.8
matTransparent 0.2
identity
translate (1,1,-4)
yRotate 0.7855
scale (2,1,3)
phongSRT
ellipsoid		// a rotated ellipsoid centered at (1,1,-4)
//
matTransparent 0.7
identity
translate (-1,1.5,-3.7)
ellipsoid

lenhart@cs.williams.edu