Sunday, June 24, 2007

[GPU] Ocean simulation

I have been working on my ocean simulation again - It's been a lot of fun to 'resurect' this code.

The two main improvements are the addition of foam, and the 'sparkles' in areas reflecting the sun. I also added a very bad looking boat (ok, this will require more work ;-)

I was afraid adding foam would be difficult, but actually the simplest approach turned out quite well. The foam is a (toroidal) texture mapped onto the sea.

The texture I use is shown here - notice it is very dark - That's because I simply add its color to the sea color.

The foam layer is multiplied by a spatially varying control value. When the control value is 0 the foam is invisible, when 1 it is fully visible. The idea is to have foam appear where the sea surface becomes rough. To do this, I am simply using (1-sea_nrm.z) as the control value. It does work reasonably well. One improvement could be to 'blur' this control value a little bit, but the current approach seems sufficient.

Last trick: To avoid obvious repetitions, I in fact add two versions of the foam texture with different scaling values. (eg. One is repeating every 2.7 units, the other every 3.14 units).

The second improvement is the addition of 'sparkles' of light. If you've been lucky enough to witness great sunset on the sea, you may have noticed all these small 'random' light sparkles in the distance. These are due to small waves reflecting the sun light directly into your eyes. I was hoping that adding sparkles would give a better impression of detail in the distance. (Especially because we do lose detail in the distance due to filtering of higher-frequency waves).

The sparkles are generated in a post-processing step. First, I render the scene in a render target. I use this texture to compute a 'probability' for sparkle appearance. Basically, sparkles are likely to appear in areas reflecting the sun light.

Second, I render the sparkles in another render target. I use a random number generator and compare its output to the probability of appearance. If the random number is large enough a white pixel is output. Otherwise a black pixel is written. Of course the generated random numbers vary with time.

This image shows the 'sparkle' layer which is directly added to the final result. I was quite happy with the result - even though it is perfectible. I think it is quite successful in increasing the impression of detail on the ocean surface.

To conclude, here is the final result. Hopefully you can see the sparkles even at this resolution.

Next I am planning to add the reflection of the boat in the sea and implement some more credible boat dynamics (not sure about this one - will depend on the gameplay).

Of course I'd like to improve the boat model / rendering. My plan (in a world with no time constraints) would be to create a boat race - or a 'boat-war' game. So if you are a modeler please send me your best creations ;-)

Saturday, June 23, 2007

[system] Transfering my blog

I am transfering my blog to blogspot ...
This is a first post to try it out.

Cheers -