Real-Time Simulation of Water Surfaces
by Thomas Schiwietz, July 2003
Testing and evaluating modern graphics hardware for numerical computations has been the main goal of my thesis. First I have implemented a discretized formula of the wave equation simulating water surfaces. Due to the lack of rendering performance of displacement maps on state-of-the-art graphic cards, my original thesis topic has been supplemented by a secondary topic. The much more sophisticated follow-up project was the solution of fluid dynamic problems using the Navier-Stokes equations. Both projects use pixel shader 2.0 programs all over the map for numerical computations. No mathematical CPU support is needed.
Download thesis text (in german)
1. Simulation of water surfaces with the wave equation
First the wave equation with a right hand side expressing the spreading of waves over time is calculated explicitly and entirely in pixel shader 2.0 programs. This results to a height-map texture with 32-bit float values per component. From there I implemented two different viewing techniques.
The straight-forward approach shows the height field from above as seen in the left screenshot below. Interactively the user can drag the water by clicking the left mouse button. Viewing the height map in 3D without interaction by the CPU requires displacement mapping which was introduced in DirectX 9.0. Vertices can be displaced by sampling a displacement map in vertex shaders. Since there are only very few graphic cards supporting displacement mapping and the rendering performance is pretty poor, the number of grid cells can be no more than 64 squared in real-time applications.
Both viewing techniques calculate light reflections and refractions to simulate surrounding environments addressed by cube maps. Additionally the Phong illumination model is applied.
Two dimensional water demo on the left hand side, three dimensional displacement mapped mesh on the right hand side.
2. Simulation of fluids with the Navier-Stokes equations
Simulation of fluids has many areas of application in engineering sciences. Since the Navier-Stokes equations are time consuming to solve, people always look for faster implementations. This approach runs entirely on modern graphics hardware and has proven to be fast. The drawback is the lower accuracy compared to traditional implementations on the CPU. Again all computations are done in pixel shader 2.0 programs without help of the CPU at any time.
A staggered grid is used to discretize the area instead of a collocated grid to provide numerical stability. All Navier-Stokes terms except pressure are solved explicitly. The pressure is computed implicitly using a conjugated gradient approach provided within the clFramework. The clFramework itself is entirely pixel shader based, too.
This is a two dimensional Navier-Stokes implementation. Extending it to three dimensions is straight-forward, but expensive. While I used 256 by 64 grid cells in 2D running at about 70 frames per second on Radeon cards, 3D demos would be much slower.
Below there are screenshots of the popular Karman vortex street and a wind tunnel.
Thomas Schiwietz, July 2003, Munich