Water

On this example, i added a reflective water effect. The theory behind is very well explained on a article on gamedev.net by Yann Lombard ( http://www.gamedev.net/columns/hardcore/rnerwater1/ ). The algorithm is the following :

  1. clip the upper-half part of the world (clip with the water plane), inverse it according to the plane of the water and render it in a texture. Let's call that texture waterTexture.
  2. clip the under-water part of the world and render it in the same texture waterTexture, but with a transparency coefficient.
  3. render the water mesh by projecting waterTexture on it :
    1. calculate the normal at every vertex of the water, according to a wave model. I have chosen a very basic sine model because it gives the normal very easily.
    2. let's call P.xyz the coordinates of the vertex. Instead of passing P to the projective matrix to get the texture coordinates onto waterTexture, we displace P on the plane of the water according to the projection of the normal on this plane.
    3. project the waterTexture onto this plane mesh.
  4. render the moutains

Details :

The following pictures are going with the options i have incrementaly added. First ones are pretty simple and the last one is the more advandced. Of course, the animation of the water is better to see in real-time that on screenshots, but i need to optimize a bit the program...


Download

download  : water.ace ( 2302ko) (exe+source+projet Visual C++ 6.0)

download : water.ace ( 2225ko) executable version with MFC to set up parameters (shadow, transparency, wave model...)

 


Screenshots Gallery

overview of the results ( reflective water and transparency, no clouds, water is not disturbed)
 
water is too transparent here, it's hard to get what is reflection and what is the under-water ground
( reflective water and transparency, no clouds, water is not disturbed)
 
water is very reflective here and hardly not transparent
( reflective water and transparency, no clouds, water is not disturbed)
 
water is at the maximum of reflection, details of the moutains in the water are well represented
( reflective water, no transparency , no clouds, water is not disturbed)
 
water is at the maximum of transparency, the green texture of the under-water part is good looking
( reflective water and transparency, no clouds, water is not disturbed)
 
same as previous one but with a bit less transparency
( reflective water and transparency, no clouds, water is not disturbed)
 
reflected sky ( water is purely reflective here), in the upper-left corner, one can notive an edge of the sky-box.
( reflective water and clouds, no transparency,  water is not disturbed)
 
the almost final picture : tranparency, reflection (mountains and sky), shadow...
( reflective water and transparency, clouds, water is not disturbed)
 
zoom on a fine part, one can notice an artefact on the left side of this picture, where water is meeting the mountains, some pixels are visible...
( reflective water and transparency, clouds, water is not disturbed)
 
one can notice here that the reflection is perturbated.
 
 
evrything is turned on, except that under-water part is not perturbated
 
on this picture, i add perturbations to the under-water part
 
 
the final picture : everything is turned on

 

 
 
 
a little problem : because coordinates are perturbated before being passed to the projective matrix, this blue-sky pixels appear.
 
 To correct this, i set the clipping plane a bit under the water plane when rendering the inversed upper-side of the world

 

 

 

 

Author :  Adrien Auclair  
adrien.auclair at club-internet.fr
Last update : 15/10/2004