This project is read-only.

Light Clip Volumes and Stencil Optimizations

Ambient and directional lights are rendered using a full screen plane and ignoring the sky fragments. However spot and point lights use stencil optimizations as the proposed by Shawn Hargreaves.

XNA does not allow sharing the GPU depth buffer therefore the GPU depth buffer has to be recreated from the G-Buffer. The G-Buffer representation does not match the GPU representation and precision problems could occur in the transition. However, this stage does not need precise information (as the material pass optimization does, but a bias was hard coded to reduce most of the problems) and therefore this recreation works fairly well and with a tolerable cost.

The clip volumes implementation works fairly similar to Killzone 2 implementation (but the depth comparisons are performed in inverse order to reduce special cases). Similarly, far lights are rendered with a cheaper shader version and I suggest looking for the best suitable threshold for your game.

The clip volumes could be changed by light to remove light bleeding without calculating an expensive shadow map and actually improving performance because fewer fragments will be processed.

If we create in a authoring tool a clip volume as the showed in the following picture.

The blue lines are the clip volume normals.

And create a point light using this same model then...


The interior of the building is not affected by the point light.

However, special consideration has to be take in the clip volume creation. Two sides should never overlap or something like this could happen.


Important: stencil optimizations were not performed in the spot lights yet nor the default clip volume uses a cone. The algorithm is very similar to point light and it is easy to finish this implementation.


Hargreaves, S. (2004). Deferred Shading. Game Developer's Conference '04.
Valient, M. (2009). The Rendering Technology of KillZone 2. Game Developer's Conference 2009. San Francisco.

Last edited Feb 5, 2013 at 6:11 PM by jischneider, version 5


No comments yet.