Now, once I had a terrain object I thought it would be great to get a water model to go with it. I thought I would just use the terrain class and modify it so that it was flat. I then needed a shader to do my water effect, and being new to all this 3D stuff and HLSL, did not have the skills to write my own, so I had a mooch on line and found NVIDIA's Ocean shader, with a few tweaks I got it working with my engine.
I am going to give you the whole class at the end along with the modified shader. What I will do now is show the effects of various parameter setting's.
Here is a basic implementation of the class
As you can see, in the picture above, I am reflecting the surrounding skybox and the bumpmap is also applied. The wave amplitude and frequency are set to 0 so you cant see any waves in this example.
This is the bumpmap I am using to ripple the surface of the water
If I remove the bump map from the render this is the effect
Kinda takes the depth out of the water doesn't it.
You can manage the bump height with the BumpMapHeight parameter
The initial picture above uses the default BumpMapHeight of 0.1 the best range is from 0 to 2, so here are both those extremes
With a BumpMapHeight of 0, the water renders like still water, no ripples at all.
With a BumpMapHeight of 2, the water renders like a raging river
OK, I will now set the BumpMapHeight back to default and start creating some waves.
As you can see this is a nice wave effect, this was done by setting the wave amplitude to 1 and the frequency to .1
Lets see what this looks like now with the maximum recommended BumpMapHeight of 2
Now that just makes me feel a little sea sick...
All the examples so far have been setting the DeepWaterColor to Navy, ShallowWaterColor to DarkSeaGreen and the ReflectionColor to DarkGrey, but as you guessed you can alter these colors too.
So with the following parameter settings
You get this effect (keeping the frequency and bump height map as before)
Just to clarify the DeepWaterColor and the ShallowWaterColor parameters. In the next image I have set the parameters like this
Giving this result
You can see the water closest to the camera is Gold colored where the water in the distance is Red, this gives that deep ocean effect.
"HALO" sparkle effect
In the origional shader you could either have this effect on or off, this is now switchable via the sparkle parameter.
So what if you want to be able to see the fish swimming in your Ocean? Well you can do this by simply setting the AlphaBlendColor parameter like this
So here is the ocean rendered without the AlphaBlendColor parameter being set and then with it set as in the code snippet above.
You still get all the lovely reflection and bump effects, they are just now rendered against a transparent mesh.
This is a very configurable shader and coupled with my RCWater class is easily accessible. As you can see in the images above it can be used in a variety of ways and I have only really touched on the possible parameter variations. However, this shader is GPU heavy, but then I am running it on my laptop which is not exactly designed for high performance 3D rendering.
So my next post will be on my Fire class and it's shader.