Friday, August 17, 2007
Generic XNA - SM3 Fog
So here is the SM3 (Shader Model 3) HLSL fog. Now this is taken pretty much 99% from Leaf's example, but thought I would comment on how easy this technique is to put into your existing shaders.
I also found that adding this to a shader pushes the operation count up a fair bit, the limit in SM2 is 64 operations per shader, so 128 in all, 64 in the Vertex Shader and another 64 in the Pixel Shader. So What I did was put the fog code into a second pass so giving me another 64x64 operation slots to play with.
So here are the shaders:
This first shader is the one used for the buildings you see in the shots, it is a single pass and a simple texture shader.
This is the shader I use for the floor tile, again this is a single pass. Just a variation on the theam really.
And finaly this is the shader used for the sky box, now, you may think, why is he using a sky box when he has such dense fog? Well it is here as an example and this is where I have put the fog calcs into the second pass so you can see how to do it (or rather how I did it)
Mouse rotates camera
Arrow Keys translate camera
Esc to exit.
Thanks to Leaf for his example on the XNA UK User Group Without it I would not know how to do it...