<!--#set var="name" value="Programming Assignment 3" -->
<!--#include virtual="header.html" -->
<!--
<head><title>COS 526, Fall 2006: Programming Assignment 3</title></head>
<body bgcolor="#ffffff" text="#000000">
<center><h2>COS 526 - Advanced Computer Graphics</h2></center>
-->


<h2>Programming Assignment 3: Path Tracer</h2>
<b>Due Tuesday, Dec. 12</b>

<p>
For this assignment, you will implement a Monte Carlo path tracer.
Your program must do the following:
<ol>
<li> Randomly generate multiple primary rays for each pixel.
<li> Trace the rays into the scene (see <a href="http://www.cs.princeton.edu/courses/archive/spring06/cos426/lectures/05-raycast.pdf">CS 426 notes</a>
for details).
<li> Terminate tracing paths with Russian roulette
(see <a href="papers/arvo90.pdf">[Arvo 90]</a>).
<li> At each intersection, generate two secondary rays: one to estimate
the direct illumination (i.e., a ray to a light source), and one to
estimate indirect (specular and diffuse) illumination.  The latter ray should
be generated using <a href="papers/lafortune94.pdf">importance sampling</a>
according to a Lambertian + Phong BRDF.  Be careful to weight these terms correctly
when combining them.
</ol>


<h3>Getting Started</h3>
<p>
You may begin with any ray tracing code you may have.  However, 
the simplest option is to use the started code provided in this
<a href="asgn3/assn3.tar.gz">tar file</a> 
or <a href="asgn3/assn3.zip">zip file</a>.  This code is an extended version of the
code provided for assignment 1.  As before, it has packages for basic geometric
primitives (points, rays, planes, triangles, etc.).  However, there is a new package,
called R3Graphics, that contains code to represent scenes with many types of
shapes (cubes, spheres, triangles), material properties
(brdfs, textures), cameras and viewports, etc. In particular, it contains
code to read a scene from a .ray file, intersect rays with many types of primitives,
etc. 

<p>There are two example programs provided that make a good starting
point for this assignment (apps/rayviewer and apps/raytracer).  The first
provides an interactive viewer for rays eminating from a camera and intersecting
primitives read from a .ray file.  The second provides a framework
for an off-line path tracing program -- it reads a .ray file and writes an image
file.

<p>The starter code provides a function (R3ReadRayFile in R3Graphics/R3Io.C) to read
scene files described in .ray format.&nbsp; The syntax of the .ray file format is 
described <a href="02/assignments/raysyntax.html">here</a>.&nbsp;
Those of you who took CS426 will recognize it as a subset of the .ray file
format used for the ray tracing assignment (with a few minor changes).&nbsp;
Most significantly, groups with arbitrary transformations are not included,
which makes intersection and sampling of rays much simpler. A repository of
sample .ray files is provided <a href="02/assignments/rayfiles/">here</a>.

<p>The starter code also provides a class to read, create, and write images.
By default, the class supports reading and writing files in .bmp and .ppm formats.
It also can support .jpg format, with the help of the jpeg library provided at 
ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz.   If you wish to work with
jpeg files (they are smaller), download the jpeg distribution tar file,
compile the for your platform, put the include file and lib file in 
a place that the R2Images class can find them (i.e., jpeglib.h should be 
placed in pkgs/jpeg and libjpeg.a should be placed in lib/), and then comment
out the "#define OMIT_JPEG" directive in R2Shapes/R2Images.C.  Of course, this
is not required.

<p>It is recommended that you develop
incrementally (implement in small steps, and test each step separately) and
that you do most of your testing on simple, well-designed examples (simple
scenes, small images, few paths per pixel, stresses feature of interest,
etc.) because execution/debugging times will be quite long otherwise.

<p>The trickiest part of the assignment is to get the importance sampling right.
Perhaps the <a href="lectures/importance.doc">notes</a> by Jason Lawrence, 
a student in the Fall 2002 class, will help.



<p>
<h3> Submitting </h3>
<p>
Please make your writeup and code accessible via the web, and send the URL
to <tt>funk@princeton.edu</tt> with "COS526" in the subject line.  Please
see the <a href="assignments.html#submitting">general notes on submitting
your assignments</a>, as well as the
<a href="assignments.html#late">late policy</a> and the
<a href="assignments.html#collaboration">collaboration policy</a>.

<!--#include virtual="footer.html" -->










