The main attraction of my project is dynamic shadows using shadow mapping. Originally, this was going to be an indoor scene of a tavern, but I thought that an outdoor scene would show off dynamic shadows better.

Shades of Green

Shades of Green is a jungle scene with dynamic shadows, using a direct light, the sun, as the only light source. Included in the scene are many trees and grasses, as well as a boiding group of bats. There is also a day/night cycle. The user can move around the scene with WASD keys and the mouse.


1. Shadow Mapping

       Shadow mapping in Shades of Green is done in the modern way, as a two-pass rendering:

  • A frame-buffer object (FBO) is created that holds a generated texture buffer.
  • The FBO texture is set to only render depth.
  • On the first render pass, the data is rendered to the FBO texture instead of the screen and using a dedicated shader program. The scene is rendered in the orthographic perspective of the light that will be used to do shadow casting (from the light's position).
  • The second render pass then renders to the screen as usual, except also sends the newly created FBO texture and associated depth coordinates to the regular shader program.
  • The shader then uses the shadow texture and the depth coordinates to determine what fragments to darken, creating a shadow.

  •        The result of using the shadow texture and coordinates to darken fragments in the fragment shader: Shadows!

    2. Anti-aliasing

           Included in the complex subject of shadow mapping, is aliasing. Shades of Green has two types of anti-aliasing: Percentage closer filtering and Poisson sampling. Poisson sampling uses an array of 16 pre or algorithmically defined values. For this project, I used pre-defined poisson values.

           Above is percentage closer filtering (PCF). If you look hard enough, you can see the texels on the edge of the shadows. This is actually being used in tandem with a four sample poisson filter (using the first four poisson values). The large projection frame causes the texels to become more noticeable, so it's generally recommended to keep your projection frames small (create shadow maps for small parts of larger scenes, instead of just once for a large scene) in order to get better quality shadows. For this project though, I used a large projection frame, because for each light in your scene that you would like to use to cast shadows, you must do another rendering pass. This way, while the shadow quality is not great, I can only do two rendering passes instead of three or four.

           Above is stratified poisson sampling. Notice the noise this time on the edge of the shadows. This method chooses different samples for each pixel, thus creating the noise. To use stratified poisson sampling, you pick a random index in your array of 16 poisson values, instead of only using the first four (like in PCF+poisson). The poisson values you choose will change the noise of your shadow. Play around with them a bunch and you can get your shadows looking nice!

    3. Other Features


  • A group of boiding bats fly in the sky, casting shadows on the ground and the trees.

  • A day/night cycle changes the position of the light and its color.

  • Pressing X will speed up time during the day.

  • Pressing Z will switch between PCF+poisson and stratified poisson sampling.

  • Pressing F will let you fly around the world.

  • There's a treasure chest randomly hidden in the world! See if you can find it!

  • Controls

  • W: Move forward

  • A: Move left

  • S: Move back

  • D: Move right

  • F: Toggle fly mode/Walk mode

  • Z: Toggle PCF/Stratified poisson filtering

  • X: Toggle time speedup

  • C: Toggle inverted y-axis mouse controls

  • MOUSE: Look around