CS 248: Introduction to Computer Graphics
Pat Hanrahan
Assignment 4
Handed out: | Thursday, February 26, 1998 |
Due: | 5pm, Tuesday, March 10, 1998 |
Note: Late days cannot be used for this assignment since
we need to grade it right after the due date in order to turn in final
grades on time. If you need to take more time, we will need to turn in an
incomplete for your final grade; please send e-mail to Prof. Hanrahan to
arrange this.
Overview
This assignment is designed to familiarize you with illumination and
shading models used in computer graphics. In this project, you will
implement functions that describe how a surface appears in given lighting
conditions. Your functions will be integrated into a interactive viewer
that we provide for you. Your shading function will be evaluated at many
points on the surface.
Many graphics systems such as OpenGL have a fixed illumination model that
describes how objects will appear in given lighting conditions. In the
case of OpenGL, this illumination model is expressed as a formula. You
have some ability to modify how this formula behaves by changing parameters
of this formula, such as the material properties of the object being
displayed and the color and position of the lights in the scene.
A more general approach to illumination is to allow a user-defined function
to be called whenever the color at a particular point on the surface needs
to be computed. This function (a surface shader) has access to
information about the scene such as the location of the point on the
surface being illuminated, the location of the light sources, the
properties of the surface, and the parameterization of the surface
(ie. texture coordinates). Using this information, the function computes
the color of the point on the surface using some model of how lighting in
the environment interacts with the surface.
You can also think of calling a shading function (called a light
shader) every time you need to know the color of a light in the scene.
This allows you to implement lights whose intensity or color changes based
on the outgoing light direction. It also allows you to write a light
shader that simulates a mask in front of the light source as follows: Every
time you call the light shader, the ray from the point on the surface being
illuminated to the light source is intersected with the mask. If the ray
passes through an "open" part of the mask, the point on the surface is
illuminated. Otherwise, it is left in darkness.
What you need to do
First, start by reading the online guide
we wrote to getting started on this assignment, which is linked off of the
class Web pages. Then, you need to implement the following six shaders:
Surface Shaders (16 points each, 64 points total):
- Bump mapping. Given an object that is parameterized by
texture coordinates (u,v), write a shader that locally perturbs
the surface normal to give the illusion of bumps. Use a simple diffuse
shading model for the surface color. Use one light and a surface color of
gray.
- Wood. Use a noise function like the one discussed in class
or the one from the online example to implement a 3D wood texture.
Experiment with the parameters to the noise function and with colors to get
a good looking wood texture. Derive the 3D texture coordinates from the
object-space coordinates of each vertex (in info.h, these are
called rawSurfacePosition), rather than from the texture
coordinates. You'll have to scale these positions down to lie in a
suitable range (between 0 and 1, for example). The size of the object's
bounding box (in info.h, this is given by
objXMin, objXMax, etc.) will be very helpful in doing
this.
- Marble. Use a noise function like the one discussed in
class or the one from the online example to implement a 3D marble texture.
Experiment with the parameters to the noise function and with colors to get
a good looking marble texture.
- Real surface. Pick a real surface (one from your room,
outside your window, or perhaps from our page of
sample real-world surfaces and write a shader to recreate it. Document
the choices that you make while implementing it and submit it as a README
file.
Light shaders (18 points each, 36 points total)
- Projected texture. Write a shader that shades a surface
(using any surface shader, like the ones above) that is illuminated by a
light with a stencil in front of it. Implement the stencil as a
black-and-white image that you can place in front of the light source. Any
light ray that passes through a black area on the image does not illuminate
the surface, and any light ray that passes through a white area on the
image illuminates the surface. Any light ray that misses the image
entirely also does not illuminate the surface. Design your own stencil
image, or use one of the samples from the assignments directory.
- Disco ball. Write a shader like the previous one that
produces a disco-ball like effect as follows: Instead of using a planar
stencil derived from an image as in the previous part, use a
procedurally-defined mask consisting of small holes (circles or other
simple shapes). The easiest way to think of the stencil is that it is
spherical mask around the light source.
Extra Credit
For extra credit, you can implement additional shaders. Two well-done
interesting shaders are worth ten extra points. Less interesting shaders
are worth fewer points. Here are a few suggestions; if you have other
ideas, please send mail to cs248@graphics to make sure your idea is ok.
Surface Shaders
- Ripply Water: write a bump-map shader that simulates windswept
water and combine it with reflection mapping to generate
good-looking water.
- Thin-film interference: if you look at a compact disc, or a puddle
of gasoline, you'll notice a rainbow of colors, caused by thin-film
interference of the light. Write a shader that simulates this.
- Moldy donut: use bump maps and an interesting surface reflection
shader to make the torus model look like a moldy donout.
Submitting
To submit this assignment, you need to do two things:
- First, run the
/usr/class/cs248/assignments/assignment4/submit
script which will submit the file shader.c, which contains
all of your shaders, the *.cfg files that define the parameters
to your shaders and their default values, and your README
file containing the
description of your real-world surface shader, plus any other items
you would like to point out to your graders.
- You also need to prepare images that you have rendered using your
shaders and put them on a web page. For each shader, you should
save a PPM file from the viewer. Copy these files to your WWW directory
and make a small web page with links to the images. There is a
template web page in
/usr/class/cs248/assignments/assignment4/248.html
which
you can use as a starting point. Please verify that all of the
links on the web page are correct.
Copyright © 1997--1998 Pat Hanrahan