New version as of July 7th 2007 :
- Much better interface, to see the different effects without touching the shader
- Self-contained Water class which would work alone in any TV3D project as-is (really!)
- Fixed fog support for all shader models and fog types (it never actually worked in SM3.0 before)
- Overall cleaner code
- Bloom!
- Lyon/Blinn specular reflections for long grazing specular highlights.
See the
in-development thread for more information.
I will not update this sample anymore. That includes ports, enhancements, new features, fixes, optimizations, name it.
Also, I have seen someone on an XNA forum that used my code and textures to build his water shader and claimed it its own. I'd really like it if anyone that uses it would at least credit me (i.e. place my name somewhere, do not appropriate my work). Also I did mention below that the textures were made using trial software, and cannot be used in a commercial project!
New version as of August 1st 2006 :
- Better specular reflection;
- Fog support for both SM2.0 and SM3.0;
- Foam sprays can be disabled with a shader pre-processor (#define);
- Recompiled with newest TV6.5 DLL;
- Cleaned the codebase a little, easier to understand and to play with.
New shots :




---
Finally, I've decided to make my shader open-source and free for everyone.
But I have one thing to ask you. Do not just take the shader and fit it in your app like a plug-in. There are TONS of customizations possible with the parameters, constants and compilation flags in the shader and in the code, play with them, adapt the shader to your tastes, or even better, learn HLSL and optimize it to your needs!!
The constants should not normally be changed, but you can play with them. The parameters are the things you want to play with in normal circumstances.
And of course if you have artists in your team or are one yourself, try to make other wave parallax maps to see how it'd look like...

The shader code is fully commented so it should be readable. I commented the TV3D code a bit too.
I optimized it as much as I could considering how versatile it is. The simplest configuration takes only 34 pixel shader arithmetic instructions, but the worst-case takes 50 (which makes it compatible SM2.0). I still think it's a very usable shader in a game environment.
Edit : The 3D parallax map (shown in the screenshots) was made using a trial version of
CGSD's Bump Texture Tools, so I guess you wouldn't be allowed to use it in a commercial project. You'd need to pay for the app or make your own with another program. I've tried a couple of alternatives (
Texture Maker generators, Photoshop clouds and noise) and this prorgam made the best seamless heightmaps.
You should know that this water is great when there's nothing that collides with it, since it's just a water plane (very little polygons) and there is no vertex displacement in the vertex shader. All "depth" effects are done via parallax mapping in the pixel shader. That means that a boat on the surface of a water plane like mine would never have slopes to climb or fall from.
--
And the download link :
http://zaknafein.hjcrusaders.com/samples/Water/Water.rar (9 Mb)