reflecting water

I’m trying to create world (from heightmap) including water which is partially transparent and partially reflective. Level of transparency and reflectivity depends on distance (most transparent near the point of view and most(=fully) reflective far away).

I´ve solved the problem but I paint too many triangles and I am looking for some more elegant solution :slight_smile:

My solution:
-First step: I paint world (only above water level) and clip parts below water level
-Second step: I paint the same part of world but mirrored - this is reflection
-Third step: I paint bottom part of the world ( below water level) clipped on water level but I have to draw it transparent (more distatnce - more transparency - mirrored(=reflected) part of world is more visible) and I also have to paint these polygons sorted form front to back with enabled depth test
-Last step: I paint water (transparent)

This works but it needs many triangles to be drawn and some of them blended and sorted (from nearest to most distant)

So question is how to do it better and faster :smiley:

Well, it looks like you have at least 2 areas that you want to optimize.

  1. Efficient visible surface determination.
  2. Efficient sorting of the visible set.

Look at occlusion queries and/or portals for visible surface/region determination, in addition to some good frustum culling. And for sorting, look at BSPs or order independent methods. For the latter, check out the NVIDIA developer site and SDK samples. Also, look at the clipplane sample.

What you use will depend on how your world is structured and your hardware. Sometimes it’s not a matter of being elegant so much as it’s a matter of getting it work quickly, whatever it takes :-).

well, not exactly.

  • I calculate what is in viewable area (depends on position, angle of view, distance, triangle orientation and clipping area) and draw only triangles which fit all these conditions
    -To sort I use quick sort algorithm (and I even calculate mean value in algorithm :slight_smile: to make it as fast as possible

Problem is: It works but it needs three passes, transition between transparent and reflective is not too smooth (depends on heightmap trinagle size
) and it looks horrible when I get under water.

I think it can be done better…

you will need to flip the mesh once you’re UNDER the water, and apply different material - shader because as you might know, water looks different when seen from inside of it . also you could grab the current frame and apply a deformation shader - effect so it looks like under-water (sometimes this can be done by showing on screen a subdivided quad which uv values you smoothly move to create that water-effect inside the water) i hope you get what i mean