Thursday 28 June 2012

Simple Bumped Terrain and Water with Fog




Well here is the same skybox, terrain and ocean objects, only this time I have added the fogging effect to the shader. Naturally the class' have had to be modified to pass the fog parameters and I have added a global static class that stores the fogging parameters that are to be applied to each object in the scene.

In the shaders, I have placed the fogging code into the second pass, in the case of the sky box this is not really needed as this shader uses very few instructions, but as for the terrain and ocean shaders they both touch the bounds of the PS instruction sets for the shader model I can use (SM2 64 instructions). You will also notice that the ocean that I have had to use COLOR channels for the return values from the vertex shader, this is because SM2 will only go as far as 7 texcoord channels (TEXTCOORD7), if you have the luxury of being able to use SM3 then you will be able to change these to TEXCOORD8. I also had to remove the old TEXCOORD7 so that I could use it for my WorldPos parameter, instead of this being passed, it is calculated in the pixel shader and so elevated the channel for this use.

Also in all the shaders I have decided to manage the render states in the passes, you may want to moth this to the code, but I guess it depends on how you intend to implement it.

So the controls are the same as the last post, but you can now switch the fog on or off with F - fog on (default) or O - fog off.


GenericXNAExampleTerrainWithFog.zip

No comments:

Post a Comment