CS 445/645: Introduction to Computer Graphics
Assignment #5 (Optional)
Goal: Write a basic ray tracer with support for rendering polygonal models
Assigned: Friday, May 2, 2003
Due: Friday, May 9, 2003
Synopsis: You will write a simple ray tracer which can read in and render a polygonal model on a checkerboard ground plane. Your code will support both reflection and shadows.
Optional assignment: This assignment is optional for both CS 445 and CS 645. Specifically, you may use this assignment to replace your grade on an earlier assignment, or to bring up your midterm exam grade. If you choose the latter, your midterm grade will be replaced by the average of this assignment and your score on the exam. Note that you must have the assignment substantially working to apply it towards your midterm! This means a grade of 80% or better, which implies a working ray tracer capable of generating a reasonable image.
Working alone: Since this assignment is optional, of course, students will work individually.
Relevant software:
Details: Your ray tracer will read models in the .poly format. Several such models are given here. The format should be almost self-explanatory. Note that vertices are given as {x y z nx ny nz} and faces are given as 3 or 4 vertex indices for triangles or quads, respectively. Note: vertices are numbered starting at vertex #1. You may wish to use the .poly parsing code from earlier assignments.
You will also read in a scene description file that contains global information such as the placement of lights, and material information about the models. The scene description file will have the suffix .scene and will follow the following format:
E <float> <float> <float> The X, Y, Z coordinates of the view point
V <float> <float> <float> The X, Y, Z vector of the viewing direction
U <float> <float> <float> The X, Y, Z "up vector" of the viewport
W <int> <float> Image width (pixels) and horizontal FOV (radians)
H <int> <float> Image height (pixels) and vertical FOV (radians)
X <float> Distance from view point to screen
G <float> The y-intercept of the X-Z ground plane
C <float> Size of the ground plane checkerboard squares
L <float> <float> <float> The R, G, B intensity of the light source
<float> <float> <float> followed by the X, Y, Z coordinates of the light
(Note: all lights are point sources)
(Note: more than one light source may be specified)
O <int> The number of objects
After this header come some optional tokens, followed by a list of objects. The optional tokens are:
T <float> threshold, reflection recursion stops when ray will contribute less than this fraction of pixels color Q <int> quality, the amount of supersampling. e.g. 2 is 2x2 oversampling ~ <float> <float> <float> <float> <float> <float> ambient for checker types 1 and 2 ! <float> <float> <float> <float> <float> <float> diffuse for checker types 1 and 2 @ <float> <float> <float> <float> <float> <float> specular for checker types 1 and 2 $ <float> <float> nshiny for checker types 1 and 2 % <float> <float> reflectivity for checker types 1 and 2
The following information is then repeated for every object:
F <filename> Path and filename of the object's .poly file
A <float> <float> <float> Set the R, G, B ambient intensity components D <float> <float> <float> Set the R, G, B diffuse reflectivity components S <float> <float> <float> Set the R, G, B specular reflectivity components N <float> Set the n(shiny) coefficient
R <float> Reflectivity from 0 (no reflection) to 1 (chrome)
M <float> <float> <float> <float> Set a matrix which will transform this object <float> <float> <float> <float> Note: matrices do not accumulate; each object <float> <float> <float> <float> is transformed separately <float> <float> <float> <float>
All characters following an unknown token are ignored to the end of the line. In other words, treat any unknown tokens as you would the "//" C++ comment token.
For this assignment you need support only one object and up to three light sources, though you can get minor extra credit by supporting multiple objects. Your program will output images in some easy-to-view format. One possibility is PPM: the PPM file format is extremely simple and can be read by many programs. The ascii version of the format looks like this:
P3 # This is a PPM file. Note that it’s text, not binary 640 480 255 183 134 59 183 134 59 183 134 59 183 134 59 59 183 134 59 183 134 59 183 134 59 183 134 […]
The first line contains the header "P3", which indicates the PPM version. The next line is a comment and can say anything after the "#" character. The next two numbers are the width and height of the image. I don’t know what the next number is, but it always seems to be "255"—probably an indication that color values range from 0-255 (i.e., 1 byte). After this header information follows the actual data: the red, green, and blue intensities of every pixel in the image, in row-major order, scaled from 0 (black) to 255 (bright).
Along with your assignment you should turn in two sample scenes that illustrate your ray-tracer in action. Your ray tracer should require only one argument, namely the .scene file (adding optional command-line flags is fine). You are allowed to add new tokens to the .scene file format, but they must be optional, not required. The goal here is to enable me to easily use your ray tracer on my sample scenes without poring through your code to figure what tokens and command-line flags you've added.
Grading: The usual 10 point scale. Doing everything well earns you nine points; to get the tenth point requires adding additional features, creating particularly nice sample scenes, etc. You will lose points for bugs or not supporting required features (e.g., shadows). You will lose LOTS of points (maybe all of them) if your assignment doesn't generate at least a reasonable image out of the box!
No late days are allowed on this assignment. I have to have final grades in within 48 hours of the last exam, so there is no leeway at all in the grading schedule.
Turning in the assignment:
To turn in the project once you are completed, follow these steps:
.exe files, like fluid.exe for example. All you should be submitting should be source, models, and the visual studio project files.
Advice:
Sample results:
Here are a couple of sample scenes: a single object (corresponding image) and multiple objects (corresponding image). One popular program that can read PPM files is Irfanview.
In the past this has been given as the first assignment in the "Advanced Computer Graphics" course. You can view sample results from that assignment.