CS 248: Introduction to Computer Graphics
Pat Hanrahan
Assignment 4
Handed out: | Tuesday, March 4, 1997 |
Due: | 5pm, Thursday, March 13, 1997 |
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.
You will submit the file shader.c that contains all of your shaders,
plus a 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 will also prepare images that you have rendered using your
shaders. Full submission details will be made available by email and on the
Web page in the following week.
[email protected]
[email protected]
Copyright © 1997 Pat Hanrahan and Andrew C. Beers