We've Sprung a Leak!
We had an in-class activity where the group which came up with the best algorithm for water would receive bonus points. I did not participate in the activity myself, though I did listen in on the discussion of my group, and took notes as people battled for board space to prove their algorithm was the best. The results were as follows:
The first group stated the most obvious (and simple) route to creating water.
You start with a plane.
Seems simple enough.
Then, apply everything you would any object within your game/simulation/whatever; a displacement map to change the surface of the plane and a normal map to make the lighting (which is then applied) look good. To simulate the reflection on the water, they pitched the idea to take the view from the camera and project it to the texture of the plane.
The reflection would require the use of post-processing effects, but everything else is as simple as anything that would be applied to almost every other object in the game. Is the water opaque, so as not to be able to see what’s below the surface? What kind of displacement map is used, and how does it move? How big is the plane, and would this algorithm work for massive bodies of water?
The next idea was added to the board.
Instead of using a normal map they pitched using a cloud map for distortion, with cloud map noise, as well as using a reflection map for the lights on the water.
For the displacement map, instead of applying a single 2D map, they decided to use two passes or perpendicular maps. Essentially they’d be displacing the water twice, in two different directions, to get a better ripple effect. Another idea they expanded on was the reflection on the water. They took the view from the camera, same as before, but before they set it as the texture of the plane they flipped it upside-down, clipped it to the plane and applied a distortion.
Then to highlight the crest and trough of the waves they used selective colouring, and used the vertex shader to find where it hit the land and made a particle emitter to emit particles along the new-found “shoreline” to make it look good. Of course, don’t forget to add transparency to the plane to make it somewhat see-through, and apply god rays beneath the water. (I won’t go into the detail of god rays here…)
The next group to take a stab at creating an algorithm decided to use quad trees for displacement. This is more memory efficient and allows for more detail to be added close up. They also pitched using physics in collision; each object has a different weight and will hit the plane at different speeds. The faster and heavier the object, the larger the “splash”, or the greater the sin waves produced in the displacement map.
And then of course, climate controls pop up. A splendid idea, if you ask me, as long as you know how to use it.
Someone came up with a very particular idea for moonlight; about 4 pixels above the surface of the plane, he made another (transparent) plane whose sole purpose would be to reflect the moonlit shimmer off the water. It’s not a bad idea, but did not earn any points in the grand scheme of Dr. Hogue’s class.
Finally, the last presented algorithm mentioned the fluid simulation. Essentially, for shallow water, you would use the fluid sim to modify the texture of the plane using shaders. He also added a pressure wave and which simultaneously contained the height of the plane’s surface to aid in collision detection. He then proposed to use a cube map for the reflection off the water’s surface.
The only one to mention other forms of water was waterfalls. Using particles that flow from one source of water, and fall until they collide with another source of water (then emit a different particle to represent spray) could make a nice waterfall. In addition, anything to hit the surface of the water creates a ripple displacement effect which continues to build as it gets applied.
Underneath the water is supposed to be distorted, so apply another displacement to all the geometry seen beneath the plane. This effect would need to be a post-processed effect, and function similar to shadow mapping or god rays. The result is distorted geometry beneath a slightly transparent surface of water.
Of course, there’s still a lot missing from all of these, though no one deigned to bring it up during class. For instance, no one mentioned the fact that those objects which interact with the water GET WET!!! Simple water interactivity was completely missed! Though when you only have 10 minutes to come up with an algorithm, I suppose it’s alright to miss a few things.
My next blog post will detail the lecture that followed this activity, in which Dr. Hogue showed us the details of how the water which was used in Uncharted was created.















