| Jeff Wood - CMPS161 - Final Project - Stencil Shadow Volumes|

This is the short walkthrough of my CMPS161 Final Project (Shadows).


This program produces Stencil Shadow Volumes using OpenGL's stencil buffer. While it is a bit more complicated than this, here is the general idea:
- Draw the scene, with objects, using only a basic ambient light.
- Draw the shadow volumes into the stencil buffer (the hard part)
- Draw the scene, with objects, where the stencil test fails (also somewhat tricky, depending upon how comfortable you are with OpenGL and the stencil buffer in particular).

What is a Shadow Volume?

- A shadow volume is just the area (volume) that is being blocked from a light source by the shadow casting object (for example, the light grey area below):



How do you make shadows, using shadow volumes?

1) Once you have the basics down, you need to figure out which polygons (triangles) are facing the light source. I used triangles simply to guarantee that no side of an object (no polygon) exists on more than 1 plane (ie: to keep the object faces planar). After that is done, you can simply plug in the position of the light into that face's plane equation to see if the current face is in view of the light.

2) Rendering of the shadows takes two steps, one to project the shadow and one to hide the shadow volume. This simply comes down to incrementing the stencil buffer whenever the depth test passes on the front faces (to project the shadow) and decrementing it (to hide the volume) whenever the depth test passes on the backfaces. This sets the stencil buffer to a non zero value where the shadow volume intersects a surface (see below).



3) To actually draw the shadows you need to see which faces are actually casting the shadow (the faces who's shadows would create a silhouette). To do this you just need to check each neighboring face, and if the neighboring face is not visible then the current edge should cast a shadow.

4) Once you have an edge that should cast a shadow, you project the two points of the edge backward some distance to get the projected edge points, and just draw a GL_QUAD using the two points of the edge and the two projected points.

5) Now that you've read the over-simplification of casting a shadow, all you need to do is draw one dark rectangle over the entire scene. Since it will only draw where the stencil buffer says to it will only render the shadows where you flagged them in the stencil buffer... creating a shadow.


Screenshots

This is the graphical user interface for the program. It is pretty straight forward, the left engraved panel controls the first object and the right engraved panel controls the second object. You can move both objects around, as well as change their rotation speed to add some animation. The 'Show Shadow' check boxes allow you to turn on/off the shadows for each object, and the 'Hide Volume' check boxes allow you to toggle on/off the stenciling out of the shadow volumes. The Light panel controls the light's position, and the Density slider controls the shadow's alpha value (brightness/darkness). The Save PPMs button is for creating a series of .ppm files to use in making an mpeg.

(the screenshots and video clips are actually somewhat poor quality, the actuall running program looks much cleaner)


This is what you see when you first run the program, a yellow sphere (the light), and two cubes casting shadows on the rest of the room, and the room is simply a cube, with a cylinder resting on the lower left side (to show shadows on a unique surface):


You can toggle on/off the stenciling out of the shadow volumes:





You can move objects around, such as the light to see shadows being cast on other objects (and even on the shadow casting objects themselves):


You can also load in a different model (the only other model that works, at the moment, is the converted NeHe model of a 3D cross ... but it should be able to load all .coor/.poly files if the poly file has been converted to represent triangles instead of arbitrarily sized polygons):


And add some rotation/translation for flavor:


Videos

Using the cube model, shows the shadow volumes with the rotating cubes:
Cubes1.mpg - 10 Sec (1.4Mb)

Using the cube model, shows the shadow volumes being toggled and the shadow alpha being changed:
Cubes2.mpg - 5 Sec (695Kb)

Using the NeHe 3D Cross model, a bit of everything. Moving the light source around (stuttery due to the slider controls for the light), toggling the volumes, toggling the shadows, and changing the density:
3dcross.mpg - 20 Sec (2.8Mb)

Using the NeHe 3D Cross model, the same as above except a quicker/smaller clip:
3dcross2.mpg - 5 Sec (1.9Mb)

Credits

nVidia's Developer Site on Shadows - For help with concepts, ideas, implementation ... everything. Great reference site.

Gamasutra - For help with concepts and algorithms for basic shadow volumes. The first two images on this page (the ones helping to explain shadow volumes) are from here.

NeHe Productions - For help with implementation and algorithms. The source of the original 3dcross model (it just works great for showing shadows).

Paul's Projects - Simply an intro to shadow volumes, at least for me it was. Not too usefull since i didn't want to use any extensions, but it was a good starting point.