GPU 3D Fluids Engine

Kevin Ubay-Ubay

For my final project, I implemented a 3D volumetric fluids engine based on the Navier-Stoke's equations. My implementation is heavily influenced by the chapter written by Mark J. Harris on fast dynamic fluids in the book GPU Gems (see reference below). Essentially, at each time step, a velocity vector field is computed by approximating a solution to the current velocity vector field. An assumption that the fluid is incompressible (the density is constant) is needed to make calculations simpler. Specifically, this allows the use of the Helmholtz-Hodge decomposition theorem which decomposes the current velocity vector field into a new velocity minus the gradient of the scalar pressure field (with the gradient of a scalar field also being a vector field). The theorem also provides a way to solve for the pressure field (pressure being a force per unit area affects the fluid's acceleration and therefore the change in velocity). Given the Navier-Stoke's equations and uniform density assumption, the steps needed to calculate and update the velocity vector field are done by how advection (the transfer of velocity), diffusion (resistance to motion) and external forces affect the fluid's movement. All computations (advection, diffusion, etc.) are computed on the GPU through pixel/fragment shaders. Calculations are stored using OpenGL's 3D texture samplers with 16-bit float precision which are used to store 3D arrays of floating point numbers rather than RGB values with the velocity field scaled into the texture space. Rendering of the fluid is also done through shaders by using a raycaster which uses a ray-box intersection routine to shade a voxel (3D box cell) within the volume.

The video below shows the fluid engine in action running on a AMD Radeon HD 6550D with the first part showing the fluid by itself isolated and the next scene showing the fluid engine integrated in with a scene to show a possible application. Better performance would most likely be easily achieved by running the demo on a graphics card with dedicated memory (versus the shared memory in the 6550) as the fragment shaders make extensive use of texel fetching which easily saturates the memory bus. Due to the number of texels fetched in the fragment shaders from the texture samplers, it is likely that the memory bandwidth is a huge bottleneck when performing fluid simulations.

Video

Images

Screenshot of fluid isolated

Attempt to integrate the fluid engine into a scene (exhaust out from behind the missile) to show possible applications. Unfortunately, a disadvantage of using a volumetric (Euler grid) representation of the fluid only allows simulation of the fluid within a contained volume as can be seen in the picture above. Increasing grid resolution (quality) or size (dimension) would require a more powerful GPU to crank through the computations.

References

GPU Gems: Fast Fluid Dynamics Simulation on the GPU - http://http.developer.nvidia.com/GPUGems/gpugems_ch38.html