Part 4: Added Detail

The devil is in the details.

Bugs in the Code

At this point we've defined an environment with four completely dynamic shadow-casting light sources, but we've placed before them a perfectly static scene. To rectify the situation we need to add something moving. In accordance with the subject matter, we add swarms of bugs to flutter around the lights at night.

The bugs themselves are simple. It's their motion that counts.

The swarm is rendered exactly like the stary sky. A set of sprites is distributed randomly about an origin. In the case of the swarm, the distance from the origin to the sprite is randomized, and the rotation of each sprite is independent of all others.

Bugs only come out at night. At any given moment there are 20 bugs per light source, but the number of bugs rendered varies with the angle of the sun. This way, the swarm seems to congregate just as the sun sets and disperse just as it rises. They flicker through the light casting fleeting shadows on the billboard and the ground below.

Das Blinkenlights

Also in the interest of dynamic lighting in accordance with the subject of the scene, we cause one of the light bulbs to behave intermittently. There's no good way to grab a screen shot of this, so take a look at the demo. This effect is implemented in C++ with the following code:

    if ((blink_delay -= dt) < 0)
    {
        if ((blink_state = !blink_state))
            blink_delay = app_conf->get_f("max_blink_on")  * rand() / RAND_MAX;
        else
            blink_delay = app_conf->get_f("max_blink_off") * rand() / RAND_MAX;

        demo_bulb1.on(blink_state);
    }

At each passing of delta-t the delay until the next light toggle is decreased. When it hits zero, the state of the light is flipped and a new delay is computed. The maximum time until the next on or off event is given in the configuration file.

While this simple bit of code doesn't seem to exemplify much, it takes advantage of a fairly powerful (though perhaps obvious) aspect of the shadow map implementation in the demo. Any light can be switched on or off and the underlying shadow map generation code switches in or out accordingly. This mechanism is also called to action when the sun and moon set and rise. Fill-rate is the bottleneck, so any rendering that need not be performed, be it on-screen or off, should be optimized away.

[Introduction] [Part 1: Scene Geometry] [Part 2: Day and Night Skies] [Part 3: Illumination] [Part 4: Added Detail]