Real Time Soft Shadows
on GeForce class hardware

Sylvain Vignaud

Requirements

I assume you already know how to cast hard shadows using the Stencil Buffer.

To display soft shadows, you'll need a 3D card with:

Even a TNT2 matches these requirements.

Introduction

The basic idea is to display many times the shadows while shaking the light, and to blur them together. As GeForce hardware is not fast enough to display so many volumes at the same time, we will use time coherency to fake it. During one frame, we will display the current volume, and blur it with the volumes of the previous frames. This idea is based on Motion Blur.

Implementation

High level view

We will store the volumes in the Alpha buffer. The different steps of the Soft Shadow Stencil Volumes algorithm are:

The big problem is that, as we have only one alpha buffer, only one light may cast soft shadows.

Shaking the light

To shake the light, I add one of these eight movement to the light position:

FrameXYZ
0-SIZE-SIZE-SIZE
1+SIZE+SIZE-SIZE
2-SIZE+SIZE+SIZE
3+SIZE-SIZE+SIZE
4-2*SIZE-2*SIZE-2*SIZE
5+2*SIZE+2*SIZE-2*SIZE
6-2*SIZE+2*SIZE+2*SIZE
7+2*SIZE-2*SIZE+2*SIZE

As you can see, I select 4 corners of 2 cubes around the light, so that there are as few positions in the same plane as possible. As a result, each volume will not be totally included in the seven others.

Fading the Alpha

Fading is done by displaying a quad with the following blending mode and color:

glColorMask( GL_FALSE,GL_FALSE,GL_FALSE,GL_TRUE );
glBlendFunc(GL_ZERO,GL_SRC_ALPHA);
glColor4f(0,0,0,0.95f);

Dynamic lighting

When the light is moving, you can chose between either shaking of not the light. Both method works fine and gives similar results.

Dynamic camera

The problem with dynamic camera is that the previous volumes are not placed where they should be.
At high frame rates, the error in the positioning of the previous volumes is not significant.
At lower frame rates, the error gets too important, and we have to reduce the number of displayed volumes, by fading them out faster.
I usually display 8 volumes when the camera is static, and 2 volumes when the camera is moving.

More realistic on faster hardware

On faster hardware, you can display all the volumes at the same time during the same frame, and you will not need shadow motion blurring anymore.
The steps are now:
For volume = 0 To MaxVolume

Results

Here is a demo of this technic
Here are several screenshots of my soft shadow algorithm on a Duron 500MHz with a GeForce2MX at 20 frames per second on average:
Soft shadows  Soft shadows  Soft shadows  Soft shadows  Soft shadows  Soft shadows  Soft shadows

The author

This documentation has been written by Sylvain Vignaud - Copyright 2001-2002.
Web site: http://tfpsly.free.fr
Distribution for free educational purpose is permitted as long as the content of this documentation is not altered, and as long as you ask permission to me. Payed distribution of this documentation is forbidden as long as you do not have a written permission from me.
Main page

email : Sly