Here it is, my static ambient occlusion shader with sample and full source!
VB.NET Samplehttp://zaknafein.hjcrusaders.com/samples/AmbientOcclusion/StaticAmbientOcclusion.rar (6.76Mb)
Mirror (thanks AriusMyst) :
http://azazeldev.org/zak/StaticAmbientOcclusion.rarSee below posts for updates... last updated 03/03/2007.Screenshots



DescriptionTraditional DirectX lighting models define ambient lighting as coming from all directions, and is added as a constant on all surfaces regardless of the geometry.
Ambient occlusion acts as a factor to ambient lighting to take into account the cavities and concave areas in a model, or how much a surface is hidden from its environment.
It is calculated using ray collision tests on each vertex, and stored in the vertex colors. Then a shader takes that value and uses it to calculate ambient lighting.
Since the effect takes a
long time to generate its data, it is stored in the model and can be saved in the TVM. It's clearly a pre-process step. I saved the highest quality of occlusion (289 rays per vertex) into each model so you don't have to regenerate it; just the floor mesh which I don't save.
To accelerate the processing on multi-core CPUs, this step is multi-threaded with up to 4 threads. The code is about 99% threadsafe; I have a random bug that occurs in Release out of the IDE so it's very hard to debug... so I ignored it.
A problem with it being static is that if you calculate the ambient occlusion with all surrounding geometry, then the objects shouldn't move in relation to each other or the effect won't appear correct.
One solution to this is to calculate
self- ambient occlusion only for models that don't animate (so all TVMs) regardless of surrounding objects. Then the objects can move around and still have the correct occlusion, with a bit less realism.
The shader also has a full lighting pipeline built-in, with offset-bumpmapping (aka parallax mapping), specular mapping, and emissive mapping. It can process up to 4 point lights and a directional light in a single pass in the Shader Model 3 profile. In SM2.0 and SM2.x, the limit is set to 2 to avoid low framerates. It does not run on SM1.4 hardware.
It's also pretty much the best shader I've ever written in terms of code structure and optimization.

For more information please see the
In-Development thread.
Enjoy!