Monday, August 29, 2011

GLSL water reflections

I have been mostly working on sehle (Khayyam rendering engine) based game framework lately. There have been some new things in Khayyam - that will be the scene/level builder for it - as well. The latest addition is reflective water material.

Esk standing on near water - with ripples and reflection
You can convert all static objects (OBJ, 3DS and Collada) to water bodies - although to get realistic results, they should be bowl- or plane shaped with surface at Z zero (in object coordinates). Everything is fake, of course - there are no real waves or refraction, but only distorted reflections and transparency. But it still looks reasonably good in my opinion.

At moment there are following water properties implemented:
  • Full reflection (everything that can be rendered can be reflected, except other reflective surfaces)
  • Viewing angle based reflectivity - i.e. if looking directly down, water is mostly transparent, looking along water surface it becomes almost perfect mirror
  • Depth-based transparency - shallow water is almost transparent, deeper water becomes opaque
  • Up to 8 simultaneous ripple generators, that can be assigned to "shore" vertices of water body
At the image below you can see how the water color changes from almost fully transparent near bank to completely opaque brown at the middle of river. As the viewing angle is high, overall reflectivity is low and the colors of river bottom and water can be seen. Ripples change the apparent angle between viewer and water surface, so although sky is uniform color, ripples still show as they change the reflectivity of surface.

A river from above showing water and bottom colors
 At the next image the viewing angle is low and thus the surface of water is almost completely reflective.
A river from low angle, showing almost perfect mirror
Ripples are circular and their wavelengths, amplitudes and generation points are updated randomly over time. Thus the actual pattern almost never repeats - although sometimes it is not as nice as on the image above.

When I find some free time, I'll write the technical details about the actual mathematics in shaders. And hopefully there will be new Khayyam release too.

Have fun!


  1. Thanks for sharing this blog, this blog is very helpful information for every one.

  2. Most impressive Topic and Blog, this is very helpful Information. thanks for sharing.

  3. Thanks for sharing this blog, this blog is very helpful information for every one.

  4. Bagaimana cara menggugurkan anak yang paling ampuh terbukti aman cepat dan akurat untuk proses cara gugurin hamil ? Tindakan medis seperti kuret metode terbaik untuk mengakhiri kehamilan anda dalam praktek cara gugurkan kandungan . Sangat penting sekali untuk mengenali cara merangsang wanita agar dapat memenuhi kebahagiaan pasangan . Daerah sensitif alat reproduksi wanita merupakan salah satu dari titik rangsangan wanita . Dalam satu bulan terjadi siklus telat datang bulan atau menstruasi yang dialami bagi wanita yang sudah beranjak dewasa .

  5. You have a real ability for writing unique content. I like how you think and the way you represent your views in this article.

  6. This is a tremendous article thanks for sharing this informative information. I will go to your blog regularly for some contemporary posts.
    Visit us for Kraft Box Of Surprise.

  7. Thanks in favor of sharing such a nice thinking, article is pleasant, thats why i have read it entirely.
    Talk to astrologer