Upcoming Events
Southwest Gaming Expo
11/20 - 11/22 @ Dallas, TX

Workshop on Network and Systems Support for Games (NetGames 2009)
11/23 - 11/25 @ Paris, France

ICIDS 2009 Interactive Storytelling
12/9 - 12/11 @ Guimarães, Portugal

Global Game Jam
1/29 - 1/31  

More events...


Quick Stats
7796 people currently visiting GDNet.
2341 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!



Link to us

Link to us

  Intel sponsors gamedev.net search:   

Rendering Water as a Post-process Effect


Possible improvements

One of these add-ons that you can get with a small amount of work and yet which significantly improves the realism of the water effect is foam. It arises when the water hits the shore and at the tops of more choppy waves.

The first of them, i.e. coastal foam, can be obtained by making an assumption that foam begins at the edge (that is, at the depth equal to 0), and to a certain depth H1 remains constant, and in the range extincts completely.

Whereas the latter can be achieved by using the following formula:

where:

  • H – current height,
  • H0 - height at which foam appears
  • Hmax - height at which foam dies out.
This gives you information how much foam is visible. However, to really get it on the screen you have to sample some foam texture and multiply its colour you get by the value found above. Using a photo of coastal foam works good for that.

Another possible extension is to add the interaction between world objects and water. The basic form of interaction will be provided if you use foam as described above. Since it is closely related to the depth at the point of the water area, it will appear wherever the depth is small. As a result it will appear whenever an object falls into the water.

However, the possibilities of interaction between water and the rest of the scene are literally unlimited. By modifying height-map either on CPU or in pixel shader you can easily introduce local disturbance for instance.


Image 3 Even though I consider foam as an “improvement” it greatly improves general image quality and makes it warmer. Therefore you should regard using it as often as possible.

Disadvantages of the presented technique

Although the presented technique removes most of the defects of existing water rendering techniques listed in the section “Traditional approaches to water rendering” there is still enough room for improvements due to several drawbacks of the current algorithm:
  • It increases fill-rate as it is done in post-process and at the same time based on deferred shading. Fortunately, in most cases the water should not occupy more than half of the screen. On the other hand, often there is no need for LOD, since most of the screen pixels will be near the observer.
  • Water looks not that good at oblique angles. In order to get rid of this problem, it is possible to apply a different bump mapping technique. The alternative is to move the normal vector towards the observer for distant waves, which will improve their quality, as their back faces will be invisible.
  • In the presented approach local lights do not affect the colour of water. You can try to move water rendering before the lighting phase (we can then modify the normal data). This, however, will require modification to the existing rendering chain.

Final results and summary


Image 4 You can achieve many different kinds of water using the presented technique, from tropical warm seas to cold lakes.

The algorithm presented in this paper is a good alternative to the popular techniques used for rendering water effects. By using calculations based on the observation of the phenomenon, rather than on existing mathematical models, I have managed to achieve a realistic effect, which in the case of properly selected parameters’ values makes it possible to achieve results comparable with much more expensive models. It is also a flexible solution - the appearance of water can be controlled through a number of attributes. This makes it suitable for a wide range of effects no matter it be lakes or oceans. You can even have several areas of radically different waters at the very same time.

Besides, as it does not rely on geometry it eliminates the most common flaws of the popular techniques discussed in more detail in the section “Traditional approaches to water rendering” of this article.

A word on implementation

The provided shader has been implemented using HLSL and DirectX 9. At present it requires a SM 3.0 capable GPU to run, however, it can be heavily optimized as my main concern was to make it as readable and simple as possible.

Several textures are used in the code:

  • heightMap – height-map used for waves generation as described in the section “Modifying existing geometry”
  • backBufferMap – current contents of the back buffer
  • positionMap – texture storing scene position vectors
  • normalMap – texture storing normal vectors for normal mapping as described in the section “The computation of normal vectors”
  • foamMap – texture containing foam – in my case it is a photo of foam converted to greyscale
  • reflectionMap – texture containing reflections rendered as described in the section “Reflection and refraction of light”
Note that positionMap is part of the G-Buffer as deferred shading is used in my implementation. In the case of forward rendering it should be depth map. positionMap in my case stores data in view space whereas in the accompanying shader all calculations are done in world space to simplify things a bit. Therefore position data has to be multiplied by the inverse view matrix.

As water is rendered as a post-process effect, a full-screen quad has to be rendered on the screen with the water shader applied.

Further reading

[1] Toman W., "Deferred shading as an effective lighting technique”, IGK’2008
[2] Placeres F. P., “Fast Per-Pixel Lightning with Many Lights”, “Game Programming Gems 6”, Charles River Media, 2006, Boston
[3] Hargreaves S., “Deferred Shading”, GDC, 2004, available on-line
[4] Guillot B., “A reappraisal of what we have learnt during three decades of computer simulations on water”
[5] Jensen L. S., Golias R., "Deep-Water Animation and Rendering“, available on-line
[6] Johanson C., "Real-time water rendering - projected grid concept”, available on-line
[7] Kryachko Y. "Using Vertex Texture Displacement for Realistic Water Rendering”, GPU Gems 2
[8] Schuler C., “Normal mapping without precomputed tangents”, ShaderX 5




Contents
  Introduction
  Technique
  Conclusion

  Source code
  Printable version
  Discuss this article