Let There Be Spotlights…

…and there are spotlights. And we see the lights, and this is good.

And I am very happy with it, because it took some time to get it work correctly due to some small and annoying bugs. But the results are fine. We can add spotlights into the scene, we can put projected textures on them and they can cast dynamic shadows. They are integrated into the deferred renderer, of course. Spotlights are rendered with a closed pyramid, but is possible to use a cone instead. Bounding boxes are adjusted according to the current transform of the light frusta to keep visibility culling efficient.

The shadow map of a particular light is updated in different ways, depending on the update mode specified to the light source. In static mode, the engine renders the shadow depth map only once at the first render of the light. In dynamic mode, the engine updates the shadow map in each frame if it is visible (it is inside the view frustum and not culled by the visibility culling), and it is close enough to the viewer to see the details of the shadow. If the mode is set to always, then the renderer updates the shadow map in each frame where the light is visible, regardless of the distance to the viewer.

The renderer automatically chooses the size of the shadow maps depending on the spot cone angle, light radius (intensity), and distance from the viewer. If the size is too small, then the light map is handled as if it would be static. This simple LOD management keeps the shadow map fill rate low.

When rendering a shadow depth map, the renderer runs a frustum query for the light frustum and renders only the objects returned, using depth-only pass.

With these optimizations, the rendering runs quite good, even if there are several spotlights in the view. But, of course, there is some room for further optimization, as always. For example, the engine could use stencil tests to exclude unlit fragments from rendering on closer lights, in order to reduce the general computational and fill cost of rendering a particular light.

To demonstrate the new capabilities of the engine, I have added a headlight to the avatar. There are some pictures showing the results of the current development.

This slideshow requires JavaScript.


Posted on December 6, 2011, in 3D programming, Deferred Shading, game engine, hierarchical culling, occlusion query, rendering and tagged , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: