Alex Dunn - Shallow Water Dynamics


The shallow water simulation is a modern solution to simple water surface rendering. It's an extension of traditional scrolling bump map techniques, adding a layer of interactivity using DirectX 11 compute shaders.

The main water displacement is based on a simulation model. Water is evolved on a 2D grid representing the height of the water above the surface. Dynamic objects add to the height field by rendering them to a data texture, using a top down camera with an orthographic view discretized around the water surface.

Rendering is performed using adaptive tessellation. A grid of quads (or patches) are distributed inside a mesh representing the water surface. These quads will be used to render the water. When using adaptive tessellation with a patch grid, it is important to ensure that the tessellation levels at the edges are shared amongst neighbouring patches. This is achieved by calculating tessellation as some function of patch edge centres to camera, as patch edges are shared on a grid. Displacement is implemented in the domain shader, using the surface height field calculated when simulating the water. Finally, in the pixel shader I've combined refraction, planar reflections, specular highlights, traditional water normal mapping and some simple foam rendering techniques to give the water it's natural look. I've also added some specular sparkles by writing some high values into the HDR buffer using the alpha channel of the foam texture.

Also implemented is some basic caustics. This is done using simple shadow mapping techniques with a twist. Rather than just rendering the depth to a shadow map, I also include a function of displacement and light direction, "f(X)=dot( normalFromDisplacement, lightDirection ) * 0.5 + 0.5", to give a value between 0 and 1 representing a basic caustic approximation from the point of view of the light. Caustics are resolved using traditional deferred shadow resolve techniqes.

In summary, normal map water for shallow pools is old news. This new technique is fit for modern games as is really fast (as it's only a simple 2D fluid simulation) and looks great!

Features: