<html>
<head>
<title>
Programming assignment #1 - Basic ray tracer
</title>
</head>
<body>

<h2>
Programming assignment #1 - Basic ray tracer
</h2>

<blockquote>
CS 348B - Computer Graphics: Image Synthesis Techniques
<br>
Spring Quarter, 1997
<br>
Marc Levoy
<br>
Handout #7
<br>
</blockquote>

<p>
<hr>

<p>
<em>Due Monday, April 21, 11:59pm</em>

<p>
<hr>

<p>
The project for this quarter is to write a ray tracer.  In assignment #1, you
will assemble the basic building blocks for recursively tracing rays through
scenes composed of triangles and spheres.  A secondary goal of this assignment
is to familiarize you with the SGI graphics workstations and the software tools
that you will use during the remainder of the quarter.

<h3>The front end</h3>
<p>
The front end for your ray tracer will consist of i3Dm, a modeling program
written by Silicon Graphics, and Composer, a scene manipulation package based
on Inventor, Silicon Graphics's 3D graphics toolkit.  i3Dm allows you to
interactively define simple 3D models.  Composer allows you to interactively
assemble scenes composed of boxes (constructed from triangles), spheres, and
models imported from i3Dm (which Composer converts into triangles).  Composer
also allows you to select viewing parameters, define directional or point light
sources, and specify reflectance properties for each object in the scene.  For
scenes of modest complexity, Composer provides real-time shaded renderings as
feedback.

<h3>Your renderer</h3>
<p>
Your renderer will be a standalone C (or C++, if you prefer) program that runs
alongside Composer.  Using our X support package, you will construct a menu
containing a display window and any number of Motif sliders and buttons.  The
latter allow you to interactively control rendering parameters not supported by
Composer, of which you may have many by the end of the quarter.  Your menu
should include buttons for retrieving the current scene geometry, shading, and
viewing parameters from Composer and for saving the rendered image in a file.
We provide the routines for performing the actual file I/O.  You should also
provide a slider for controlling image size.  Finally, you should provide a
"Render" button.  When hit, you will render the scene using your ray tracer
and display the resulting image in the display window.  Don't expect your ray
tracer to run in real time.

<h3>Required functionality</h3>
<ol>
<li>
Read a scene description describing the camera, lights and a set of objects
with associated material properties from a file created by Composer.
<li>
Cast rays into the scene to simulate the image formed by a pin-hole camera.
One ray per pixel is sufficient for now.
<li>
Intersect rays with the geometric primitives.  Don't worry about speed yet.
<li>
Implement Whitted's illumination model (FvDFH, eq. 16.55), which includes
ambient, diffuse, and specular terms for each light source as well as
reflection and refraction terms.  You only need to handle directional and point
light sources, i.e. no area lights, but you should be able to handle multiple
lights.
<li>
Write an image file containing your synthetic image.
</ol>

<h3>Writing a ray tracer</h3>
<p>
Paul Heckbert's chapter in Andrew Glassner's
<em>An Introduction to Ray Tracing</em>
gives a good overview of how to write a ray tracer.  Feel free to copy his
organization and examples.  Using his nomenclature, Composer provides your
<b>SceneRead</b>
routine and defines your
<b>Camera</b>
and
<b>Display</b>
data structures.
You must write the
<b>Screen</b>,
<b>Trace</b>,
<b>Intersect</b>,
and
<b>Shade</b>
routines.  If you're having trouble converting pixel positions into ray
directions, see Glassner's <em>A Simple Viewing Geometry</em> in
<em>Graphics Gems II</em>
(handout #8).  To render triangles and spheres, you will need two intersection
routines.  See sections 2 and 3 of Haine's chapter or section 15.10.1 of Foley,
van Dam, et al.  Also feel free to use Heckbert's ray-sphere intersection code
(in Glassner).
<p>
The support software you need for this project is contained in
/usr/class/cs348b.  (A tarred and gzipped copy is available in
<a href="ftp://www-graphics/pub/courses/cs348b/">
ftp://www-graphics/pub/courses/cs348b/</a>).  Look at the README file and the
software and other README files that it references.  Although
xsupport/scene_io.h talks about ellipsoids, per-vertex materials, and meshes,
you can ignore all of these.  You only need to handle spheres and triangles,
and you can assume one material per object.  In programming assignment #3, you
are welcome to add these other features.
<p>
Design your software to be modular so that you can extend it.  In programming
assignment #2, you will add an acceleration scheme.  In programming assignment
#3, you will add one or more extensions of your own choosing.

<h3>Notes on Whitted's illumination model</h3>
<p>
The first three terms in Whitted's model will require you to trace
rays towards each light, and the last two will require you to recursively trace
reflected and refracted rays.  When tracing rays toward lights, you should look
for intersections with objects, thereby rendering shadows.  If you intersect a
semi-transparent object, you should attenuate the light, thereby rendering
partial shadows, but you may ignore refraction as explained in class.
<p>
Note that the light strengths and attenuation factors you get from Composer are
not appropriate for ray tracing.  Moreover, you are not building a
radiometrically correct ray tracer.  To facilitate debugging and grading, use
the mapping from Composer's material attributes to the terms in Whitted's
illumination model that is suggested in README.composer, scaling these
attributes if necessary to make your images look roughly like the samples (see
below).

<h3>Submission requirements</h3>
<p>
Your ray tracer should be able to handle the three test scenes test1.out,
test2.out, and test3.out in the directory /usr/class/cs348b/proj1/tests.  If
you want to look at these scenes in Composer, load the corresponding .iv files.
Also included in that directory are sample images produced by a ray tracer from
last year's class.  You should run your ray tracer on those scenes and save the
images it produces.  In addition, you should create two more scenes of limited
complexity to test your system.  Save those scenes and the images produced. The
majority of your grade will be based on your results, although we will look
briefly at your code to make sure it is plausible.
<p>
When you have completed your assignment, make a copy of your code and the test
scenes and associated images in a directory called project1 in your home
directory.  Write a README file with enough information so that we know what is
there. Then follow the instructions in /usr/class/cs348b/README.submit to
complete your submission.  Don't touch the files in that directory after the
due date.

<p>
<hr>
<address>
levoy@cs.stanford.edu
</address>
<b>Copyright &copy; 1997 Marc Levoy</b>
<br>
Last update:
Monday, 07-Apr-1997 16:42:25 PDT

</body>
</html>
