ECE4893A/CS4803MPG – Homework #4

ECE4893A/CS4803MPG – Homework #4

ECE4893A/CS4803MPG: Multicore and GPU Programming for Video Games

Fall 2012

Homework #4: Shaded First Person Shooter

Due: Wednesday, Nov. 21 at 4:30 PM (via T-square)

Late policy (lack thereof, really):
The homework will be graded out of 200 points.

Having this
hang over your head over Thanksgiving break is not pleasant. So if you’re not
finished by the deadline, just turn in whatever you have and I’ll give you
appropriate partial credit.

The goal: In this assignment, you will
create a first-person shooter that employs a sophisticated rendering
effect such as normal mapping, as well as a post-processing
The main purpose of this assignment, besides getting practice with
creating shaders and integrating them through an API, is to create
something awesome that you can demo for potential employers.

This assignment is more ambitious than the previous ones, so do
not wait until the last minute to start it.

The basics: Staring with Prof. Lee’s
excellent DungeonShooter

as a base,
develop a simple “first
person shooter” game with the behaviors described below:

  • A single enemy (we’ll only demand
    one to keep the programming simple, but if you want to put in more, go for
    which is randomly placed somewhere in the room at
    the start of the game
    (but not somewhere too close to the player),
    toward the player
    . You will need to experiment to find a good speed for
    the enemy; for the game to be playable, the enemy should not move too fast.
    The model you use for the enemy should “face” the direction it is going.
    you have time and
    want to try coding up more complex behaviors, such an enemy that can
    only “see” in a certain angular segment in the direction they are
    facing and who has to turn to “search” for the player, have fun, but it
    is not required for full credit on this assignment.)

  • The enemy moves in two dimensions (like the player) and appears to rest
    on the floor (i.e. no flying enemies.)

  • When the enemy collides with the player, the game
    A collision is declared to have occured when the enemy is within
    a certain distance of the player. You can determine a reasonable distance
    by considering the dimensions of your enemy model.

  • When a projectile fired by the player
    collides with the enemy, the enemy is destroyed and
    a new enemy is “spawned” at a random location in the room.

    To avoid the player dying too soon,
    the enemy should not respawn too close to they player (as was the
    case at the start of the game).
    A collision of the projectile with
    the enemy is declared when the center of the projectile is within some
    appropriate distance of the enemy.

  • The enemy should be represented with a complex model of
    some appropriately
    terrifying and/or amusing menace. Please don’t use the teapot, a cube,
    or a sphere; you know, use something cool.

Concerning the adaptation of Prof. Lee’s code:

  • You should keep Prof. Lee’s walls, ceilings, and floor where they
    You can use the existing textures or replace them with your own.

  • Concerning the various spinning teapots, the Mona Lisas, etc. you
    can leave them in, take them out, or replace them with decorations of your
    own choosing however you see fit.

  • Please keep the multiple light sources.

Your game does not need to have…

  • Any additional sound effects,
    since the class
    is not focusing on sound.

  • Any intro screens. You can just jump right into the game.
  • Any score keeping mechanism.
  • Any fancy behavior when an enemy or the player is killed. The
    enemy can just disappear when it is hit by a projectile; it does not need
    to dissolve or explode. Similarly, when the enemy contacts the player, you
    don’t need any 007-style dripping blood screens.

  • Any serious “tuning” or “playtesting.” This assignment is to get you
    accustomed to some issues in game programming, but is not intended in any
    way as an exercise in game design. (That said, you should probably lean
    towards making the game “too easy” instead of “too hard,” since that will
    make it easier for me to make sure everything works.)

  • Decent collision detection. We’re telling you to do something
    very simple in this assignment, so there may be times where it looks
    like things aren’t colliding and your code will say they are or vice-versa.

Of course, we are hoping you will have fun with this assignment, so if
you want to add various enhancements and have time, go to town!

The 3-D shader part: Make
the floor look much cooler by applying normal mapping to it.

(Notice I’m suggesting the floor since applying normal mapping to a plane
is much easier than appying it to an arbitrary surface.) This will involve
re-writing Prof. Lee’s multi-light shader to operate in a Phong style
instead of a Gourard style; i.e. you’ll need to shift much of the lighting
from the vertex shader to the pixel shader. You can find some normal
maps online (just do a google search on “normal maps”) – look for
images where the x, y, and z are coded as red,
green, and blue. Or, you could try creating your own normal map somehow.
(Instead of normal mapping, you are welcome to
propose some sophisticated
shader effect of your own devising. It must be similiar
in complexity to normal mapping. Before embarking on
an alternate path, be sure to discuss your proposal with Prof. Lanterman
to make sure your proposed shader
is sufficiently complex and get his approval.)
You are welcome to borrow code from tutorials, blog posts, etc. you find
online; just be sure to give appropriate credit in your comments.

If you wish,
you may choose to have the bump mapping effect only apply to one
of the light sources. It is not that much more difficult to have bump mapping
apply to all of the light sources; I am giving you the option of only doing so
for one of the light sources in case you are working with a less capable

that may run out of registers or some hit up against similar limitation. One
of the best ways to make sure the bump mapping effect is working is to
turn various lights on and off; Dr. Lee has commands for this
built into his code. If
your bump mapping only applies to one light, you should code in some sort
of motion for that particular
light – have it move around somehow – so that the bump
mapping effect is easier to observe.

The 2-D postprocessing part: Add a cool non-trivial
postprocessing effect to
your game,
something that makes sense within the context of the
gameplay. It might be an effect
that runs all the time, or when the player fires, or when the monster is
hit, or when the player dies; or, if you’ve gone all-out an implemented
some non-required gameplay enhancement, it might be associated with that
enhancement. By non-trivial, I mean that it shouldn’t just pixelwise
change the colors without some sort of interesting
inter-pixel interaction or warping (i.e. don’t do something like just swap red
and green or get rid of all the blue). You are
welcome to adapt code you find on the web or in books and such, as long
as you give the original author appropriate credit in your comments.

Package everything needed to compile and run your game
(3D data file, textures, code, etc.), along with a README file briefly
what techniques you implemented and any particular problems or issues you
might have run into,
upload them to T-square as a zip file or gzipped tar file.
Include “HW4” and as much
as possible of your full name in the
filename, e.g., (The upload
procedure should be reasonably self explanatory once
you log in to T-square.)

Be sure to finish sufficiently in
advance of the deadline that you will
be able to work around any troubles
T-square gives you to successfully
submit before the deadline. If you have
trouble getting T-square to work,
please e-mail your compressed
file to,
with “MPG HW #4” and your full
name in the header line;
please only
use this e-mail submission as a last resort if T-square isn’t working.

Ground rules: You are welcome to discuss high-level implementation
issues with your fellow students – in particular, feel free to point one
another to appropriate examples online –
but you should avoid actually looking
at one another student’s code as whole,
and under no circumstances should you be
copying any portion of another student’s code.
However, asking another student to focus
on a few lines of your code discuss why a you running into trouble
is reasonable. Basically, these “ground rules” are
intended to prevent
a student from “freeloading” off another student, even accidentally, since
they won’t get the full yummy nutritional educational goodness out of the
assignment if they do.

Looking at code from homeworks done in previous years is strictly