<html>
<head>
<title>
Programming assignment #4 - Phong shader
</title>
</head>
<body>

<h2>
Programming assignment #4 - Phong shader
</h2>

<blockquote>
CS 248 - Introduction to Computer Graphics
<br>
Spring Quarter, 1995
<br>
Marc Levoy
<br>
Handout #14
<br>
</blockquote>

<p>
<hr>

<p>
<em>Demos on Monday, June 12</em>
<p>
<em>Writeups due on Tuesday, June 13 by 5:00pm</em>

<p>
<hr>

<p>
Your assignment is to extend the Z-buffer renderer you implemented in project
#3 to include Phong illumination, Phong interpolated shading on triangle
meshes, and texture mapping.

<h3>Required functionality</h3>

<ol>

<p>
<li>
<b>Phong interpolation and illumination.</b>
During scan conversion of each triangle, calculate pixel colors using the Phong
illumination model (section 16.1 in the textbook) and, for triangle meshes,
the Phong normal vector interpolation method (section 16.2.5).  Implement an
infinite viewer and one infinite (i.e. directional) light by using the same
viewing vector <b>V</b> and the same one lighting vector <b>L</b> at all pixels
as discussed in class.  For a tutorial on these calculations, refer to the set
of online notes entitled "Shading computations for project #4".
<p>
Use the lighting information and material properties provided by Composer,
which is documented in /usr/class/cs248/support/include/scene.h.  Note that
this formulation differs slightly from equation 16.20 in the textbook.  To
facilitate debugging when an SGI workstation is not available, we suggest
providing sliders to manipulate some or all of these variables, especially
lighting direction (not required and no extra credit given).  For properties
not provided by Composer (e.g. <code>Fatt</code>), assume something reasonable
or provide your own slider(s) to specify them.  Properties provided by Composer
but not relevant to your renderer (e.g. transparency) may be ignored.

<p>
<li>
<b>Texture mapping.</b>
The shading calculations for at least one triangle must include a texture.
Applying a texture to a triangle consists of four steps:
<ul>
<li>
Choose an input texture image.  Use an image free from aliasing artifacts, such
as the alpine pasture, a grayscale or full-color scanned image, or a texture
you create from scratch using your tinting brush.  Avoid jaggy, severely
quantized, or dithered input texture images; they will look poor when
resampled.
<li>
Establish a correspondence between the vertices of the triangle and three
different points in the texture image.  Any correspondence will suffice, but it
should remain fixed regardless of the screen space position of your triangle.
<li>
Render your texture by interpolating texture map indices during scan
conversion using the rational linear interpolation method described in section
2.3.5 of Heckbert (handout #15) and discussed in class.  An online tutorial on
texture mapping computations customized for this project is in preparation.
You needn't explicitly filter your texture during rendering; your supersampling
should eliminate most aliasing artifacts (as long as you don't severely magnify
the texture).
<li>
Use your texture to modulate surface reflectance, color, shininess, or
orientation (i.e. bump mapping), or use it to modulate an interpolation between
two other textures or between two entirely different shading models.  Or
modulate surface opacity and use digital compositing when writing to the
canvas.  Be creative.  See Cook (handout #12) for ideas.
</ul>

</ol>

<h3>Submission requirements</h3>
<p>
We will follow the usual demo and submission procedure.
<em>No late demos this time!</em>
<em>Writeups are due by 5:00pm on Tuesday, June 13!</em>
The assignment will be graded on correctness (60 points), efficiency (10
points), creativity (10 points), programming style (10 points), user interface
(10 points).
<p>
Your program must be capable of reading the files output by Composer, as in
assigment #3.  We may or may not provide grader data files for this assignment.
Regardless, be prepared to show one or more precomputed images that include at
least one triangle mesh with interpolated shading.  Images should be
antialiased using your supersampling as in assignment #3.
<p>
Provide an enable/disable option for displaying a visualization of the X, Y,
and Z components of your surface normals at each pixel.  We suggest three
separate visualizations or one button-controlled visualization rather than
mapping X, Y, and Z to R, G, and B.  The latter is acceptable if you also
provide button-control over which one of R, G, or B is displayed.  We require
this visualization both to help you debug your own program and to help us
evaluate where your problems lie if any arise during the demos.

<h3>Working in teams</h3>
<p>
You may work alone or in teams of two or three.  For a team of two, you must
implement two of the following bells and whistles.  For a team of three, you
must implement five.  Alternatives are acceptable if approved in advance.  If
you have completed the assignment and wish to earn extra credit, you may add
more bells and whistles.

<ol>
<p>
<li>
Render a texture on a triangle mesh.  In this case, you'll have to establish
a mapping from sequences of vertices to appropriately spaced points in your
input texture image.  Use a mapping that is continuous across the mesh; don't
simply copy the same texture onto every triangle.  For generalized cylinders
(like vases), such a mapping is easily derived by converting triangle vertex
coordinates from Cartesian to cylindrical space, which can then be mapped to a
2D image.
<p>
<li>
Support a local viewer and however many local (i.e. point) lights are given to
you by Composer.  This will require you to compute and normalize a new viewing
vector <b>V</b> and lighting vector
<b>L</b> at each pixel as discussed in class and in the online tutorial.
<p>
<li>
Generate a solid texture that incorporates the Perlin Turbulence function (see
page 1047 and plate IV.7 in the textbook).  For additional details
(and some inspiring pictures), see
K. Perlin, ``Hypertexture'',
<em>Proc. Siggraph '89</em>,
p. 255, and
K. Perlin, ``An Image Synthesizer,''
<em>Proc. Siggraph '85</em>.
(Both are available at the library.)
<p>
<li>
Dice triangles into micropolygons as described in the REYES paper (handout #11)
and implement displacement mapping.  Specifically, use a procedurally generated
or interactively generated (i.e. painted) texture to modify the 3D coordinates
of micropolygon vertices.  See Plate II.37 in the textbook or Upstill's
<em>RenderMan Companion</em> (available at the bookstore) for ideas.
<p>
<li>
Implement texture prefiltering using mip maps or summed area tables as
described in section 17.4.3 of the textbook to yield properly filtered textures
even in severe perspectives and when triangles are rotated nearly on edge.
<p>
<li>
Develop a language to specify shade trees.  At minimum, the shade tree must
include mix nodes driven by textures as in Cook (handout #12).  Don't spend a
lot of time on the interpreter - a simple syntax will do.
<p>
<li>
Implement shadows using Lance William's Z-buffer-based shadow map algorithm
(see L. Williams, ``Casting Curved Shadows on Curved Surfaces,''
<em>Proc. Siggraph '78</em>,
pp. 270-274.  Worth 2 bells.  For even more credit, implement the improved
algorithm described in W. Reeves, D. Salesin, R. Cook, ``Rendering Antialiased
Shadows with Depth Maps,''
<em>Proc. Siggraph '87</em>,
pp. 283-291.
<p>
<li>
Any bell or whistle from assignment #3 that you have not already implemented.
If you implemented a 3D paint program, extend it so that it creates a texture
that is mapped to your mesh instead of just applying color at triangle
vertices.

</ol>

<p>
<hr>

<h3>The competition</h3>
<p>
At 4:00pm on Monday, June 12, a judging will be held to select the best
rendering.  Participation in this competition is not required.
<p>
Entries may be made by individuals or teams, and may consist of any number of
images or animations.  You are allowed to use only i3dm, Composer, the renderer
you wrote for this course, any modeling software you wrote for the course (e.g.
procedural modeler or shading languages), and tools available on our SGI, Dec,
or Sparc workstations.  You may not use GL.  If you wish to use other tools,
you must obtain approval and be prepared to make them available to all
competitors.
<p>
The jury will consist of prominent computer graphics experts from academia or
industry.  Your prof will preside.  During the judging, each individual or team
will display their entry and briefly explain any exotic techniques used in its
creation.  This process is expected to take approximately 45 minutes.  The
winning submission will then be decided in private by the jury and announced to
the gathered multitudes.
<p>
While grades for the programming project are based solely on "technical merit",
the competition will be judged on both "technical merit" and "artistic
impression".  In particular, the jury will look for photorealism, creativity,
and elegance.
<p>
There will be one grand prize - an
<b>all-expenses-paid trip to Siggraph '95</b>
in Los Angeles, August 7-11, one second-place prize -
<b>dinner for two at Il Fornaio</b>
in Palo Alto and a copy of the
<b>Siggraph '94 Film and Video Show</b>
on VHS videotape, and three third-place prizes - a copy of the Siggraph '94
videotape.  If the grand prize is won by a team, it must be split among the
team members.  All other prizes will be duplicated as necessary to cover the
team.

<h3>The party</h3>
<p>
Immediately following the render-off, there will be a party in the graphics lab
and on the terrace outside Sweet Hall to celebrate the winner, your survival of
this course, and the arrival of Summer.  Refreshments will be provided.

<p>
<hr>
<address>
levoy@cs.stanford.edu
</address>
Friday, 20-Feb-1998 15:46:51 CST

</body>
</html>
