Introduction

This project's objective was to create a game that used realtime shadows and other basic elements. The end product was a 3d game of "follow the light" complete with moving platforms, collision detection, different modes, and even rain.

Shadow Game

The purpose of the game is to follow the light as fast as possible.

Controls

Mouse - The mouse is used to control direction of view, as in a FPS
W,A,S,D - forwards, strafe left, back, strafe right
[SPACE] - jump
Y - Turn on rain
T - spawn a layer of rain
V - toggle wireframe mode
E - Toggle ligh attenuation
R - reset to last checkpoint
P - PAUSE
Q - QUIT

Compiling and Playing

The game can be compiled using the provided Makefile.
Some adjustments may have to be made depending on your computer's speed;
At the top of main.cpp are #define values to adjust:
RSPEED - Speed of rain falling
GRAVACC - Acceleration of gravity
GRAVTERM - Terminal velocity
MAXJUMP - starting jump velocity
MAXSPEED - walking speed
**TIMERINT - Update rate of all geometry and physics (amount of time to wait inbetween updates)
LSPEED - speed of the light sphere
IDLEACC - Idle hovering acceleration of light sphere
IDLESPEED - Idle hovering max speed
*RAINDENS - Rain density

** If the game is running to slow, decrease the value of TIMERINT to ~20 or less
* Also if the rain is slowing down the game decrease RAINDENS to 2 or so.

Once compiled run "shadow"

Making the Game

Shadows

After creating a simple 3d world, done in project 4 the first task was that of creating a shadow.
To create the realtime shadows, I used the method of shadow volumes, in particular the Z-Fail method.
This method creates shadows by first making a frustum around the silhouette of every surface in relation
to the light source. You extend the silhouette away from the light and add a front and back cap. Then
using the stencil buffer you increase/decrease the value of the buffer corresponding to the depth-fail in
conjunction with the shadow volume (frustum) created. This adding an increase to the back (culling front)
and a decrease to the back (culling back). Then use the stencil buffer to fill in the correct shaded regions.

The following pictures were the project, early in development, one shows a red shadow volume and the
other shows the resulting shading from the stencil buffer.

Shadow Volume Stencil Buffer Shadow

Note of advice for shadow volumes: Make sure your shadow volumes do not get clipped by your perspective matrix.
Far should be far enough, otherwise the Z-fail method will not work.

Collision detection

I implemented collision detection for all objects, allowing you to run into and stand upon all objects and slopes.
In addition I added moving platforms that move whatever is currently on top of that object.

The Light

The light changes color with time due to sine functions on my update.
The light has a series of points that it goes through, animated inbetween.
When Idle the light gravitates up and down slowly.
Once a checkpoint is reached by the player, falling off the level will result in spawing at the that last checkpoint.

Objects

Objects are all procedurally generated from primitives, and defined by six to eight numbers.
This allows for easy creation of many objects.
Objects use a concrete texture found online using functions provided by ZWood.(In tex.cpp tex.h)

Rain

The rain is an created out of hundreds of rain "droplets."
Droplets are represented as points with length and hit count.
Falling, the rain is a line extended up from its point.
Once it hits an object, it increments the hit count and draws a low res circle with radius dependent on the hit count.

Overview


Over all I enjoyed making this game and am satisfied with the outcome. It is a basic platform from wich I can build
upon and add increased functionality.

Screen Shots

A View of the World

Wireframe Mode

Game With Rain

Game with Rain

Game With Rain

Wireframe with Rain

Download

References

The Theory of Stencil Shadow Volumes
JoshBeam - Stenciled Shadow Volumes
Paul's Projects - Shadow Volumes
OpenGlDocs