Contents
Sponsored Feature: Multi-Threaded Fluid Simulation for Games
 
 
Printer-Friendly VersionPrinter-Friendly Version
 


Part of:



[More information...]
 

Latest News
spacer View All spacer
 
November 7, 2009
 
Iwata: 35% Japanese Connectivity Ratio For Wii, 20% For DS
 
iPhone Dev Storm8 Sued Over User Data Harvesting Allegations [5]
 
Game Boy, The Ball Admitted To National Toy Hall Of Fame
spacer
Latest Jobs
spacer View All     Post a Job     RSS spacer
 
November 7, 2009
 
FarSight Studios
Software Engineer
 
Sucker Punch Productions
3D Environment Artist
 
Sucker Punch Productions
Network Programmer
 
Sucker Punch Productions
Character Artist
 
Sucker Punch Productions
Texture Artist
 
Monolith Productions
Sr. Software Engineer, Engine - Monolith Productions - #113767
 
Sony Online Entertainment
Brand Manager
 
Crystal Dynamics
Sr. Level Designer
spacer
Latest Features
spacer View All spacer
 
November 7, 2009
 
arrow On Bringing Modern Warfare 2 To Life [3]
 
arrow Games Demystified: Dissidia Final Fantasy [1]
 
arrow Building Social Success: Zynga's Perspective [3]
 
arrow Small Developers: Minimizing Risks in Large Productions - Part I [7]
 
arrow Valve's Writers And The Creative Process [11]
 
arrow Sony's Software Strategy: Shuhei Yoshida Speaks [3]
 
arrow A Holistic Approach to Game Dialogue Production [7]
 
arrow Ancients Reborn: Launching League of Legends [4]
spacer
Latest Blogs
spacer View All     Post     RSS spacer
 
November 7, 2009
 
Space of Possibility and Pacing in Casual Game Design - A PopCap Case Study [1]
 
Defining "Hard Core" and "Casual"? [10]
 
Comparative Ludology: A Case Study Using The Sims and Total War
spacer
About
spacer News Director:
Leigh Alexander
Features Director:
Christian Nutt
Editor At Large:
Chris Remo
Advertising:
John 'Malik' Watson
Recruitment/Education:
Gina Gross
 
Features
  Sponsored Feature: Multi-Threaded Fluid Simulation for Games
by Quentin Froemke
8 comments
Share RSS
 
 
June 17, 2009 Article Start Page 1 of 2 Next
 
[In this Intel-sponsored feature, part of Gamasutra's Visual Computing section, Intel engineer Froemke describes a multi-threaded fluid simulation system created to make virtual smoke or water for application into games, including an executable demo and source files for the 'Kaboom' system.]

Along with mentioning a strange rash, a sure way to kill a conversation is to bring up the topic of Computational Fluid Dynamics (CFD). But for those who wish to create fantastic-looking clouds, explosions, smoke, and other game effects, nothing could be more exciting!

CFD is the section of fluid mechanics that finds numerical solutions to the equations describing the behavior of fluids, both liquid and gaseous, and their interaction with various forces. Until recent hardware advances, even approximating a solution was too computationally intense for real-time applications.

However, the last year or two has shown a small but increasing amount of research and articles, as well as the release of some commercial products that deal with simulating fluids, not only in real time but in a video game environment.

With the Kaboom project, we've created a modular, threaded CFD simulation that can be dropped into an existing project, hooked up to a rendering engine, and used to generate realistic, real-time fluid dynamics simulations, suitable for smoke or water.

We observed that many games are not reaching their full potential because they're unable to use all of the available CPU resources. Frequently, this is because they are not properly threaded for multi-core architectures.

Rather than run the simulation on the GPU, we decided to use those extra cycles to produce a basic, real-time fluid simulation. By performing the simulation on the CPU as opposed to the GPU, the simulation has fast and easy access to all game resources (such as mesh information) and the game has access to the simulation results. This also leaves the GPU free to handle the graphics.

As we continued our research we found that although interest in fluid simulations was high, little concrete material was available, especially in the way of code and examples. We were unable to find examples of 3D or multi-threaded solvers. Most of the articles described ways to solve the equations but did not use a multi-threaded approach.

Despite this, there seemed to be a lot of interest in the topic, so we decided that another goal of the project would be to make the resulting code modular and thereby fairly simple for someone to integrate into their own project. Developers can also use and expand upon the set of threaded, modular routines that we created for 3D CFD.

Simulation

The code is based on an article series and sample code written by Mick West that was recently posted on Gamasutra.1,2 Since one of our goals was to produce a modular, reusable code base, the first thing we did was to convert the existing sample to C++ and separate the simulation from the rest of the application, specifically from the rendering.

This separation allows the simulation code to be easily added to an existing code base and rendering engine.

Next, we extended the code into three dimensions, which turned out to be a fairly straightforward exercise because none of the algorithms changed appreciably with the addition of another dimension.

For example, the 2D diffusion step is solved by applying the diffusion operation to move values from a cell to its neighbors (Figures 1 and 2). This approach is extended in the 3D case so that instead of inspecting four neighboring cells we look at six neighbors (Figures 1 and 3). Other cases used the same principle as well.


Figure 1. Transitioning code from 2D to 3D.

The following two code samples (Figures 2 and 3) show the code that performs the diffusion operation for non-border case cells in both the 2D and 3D cases. The border cells are those cells at the very edge of the grid that are missing one or more neighbors.

These cells are handled separately as special cases. The transition to 3D is accomplished by adding in consideration for the z-axis. Apart from that, the algorithm remains essentially the same.


Figure 2. A code sample that shows 2D diffusion.


Figure 3. A code sample that shows 3D diffusion.

After transitioning the simulation into 3D, we began investigating how to break the work up for parallel processing. As a base for our multi-core work we used the Intel Threading Building Blocks (TBB) package.

We found TBB to be very competitive in performance with other threading APIs. Additionally, it has a lot of built-in functionality and structures, such as a thread pool, task manager, and multi-threaded memory management.

The idea behind threading the simulation is data decomposition: take the grid and break it into smaller portions. These smaller portions are submitted as tasks to the task queue and processed by the worker threads, independently of each other.

The grid is broken up evenly until a small-enough granularity is reached, at which point further reductions become ineffective, or worse, inefficient due to thread management overhead. Figure 4 shows an example of how a 2D grid is broken into four tasks.

1 West, Mick. "Practical Fluid Dynamics: Part 1" Gamasutra, 26 June 2008. http://www.gamasutra.com/view/feature/1549/practical_fluid_dynamics_part_1.php

2 West, Mick. "Practical Fluid Dynamics: Part 2" Gamasutra, 23 July 2008. http://www.gamasutra.com/view/feature/1615/practical_fluid_dynamics__part_ii.php

 
Article Start Page 1 of 2 Next
 
Comments

Nicholas Sherlock
18 Jun 2009 at 12:06 am PST
profile image
The executables zip file is protected by a password??

Mark Miller
18 Jun 2009 at 5:45 am PST
profile image
My first guess was "intel" and I was right :-).

Simon Carless
18 Jun 2009 at 6:23 am PST
profile image
Apologies - I'll post again when this is fixed.

Ondrej Spanel
18 Jun 2009 at 12:19 pm PST
profile image
The archive does not contain necessary dlls, and it even does not tell what dlls are needed or where could one get them.

So far I have found:

tbb.dll (Thread Building Blocks)
MSVCP80.dll (Some version of MSVC runtime)

Not knowing where to get them, I am unable to run the demo.

Jeff Freeman
18 Jun 2009 at 2:54 pm PST
profile image
The accompanying Readme.txt files notes build requirements. Legal requirements prevented us from including some of the redistributable binaries.

Cheers,
Jeff

Running the Application
-----------------------

Redistributables
----------------

If Visual Studio 2008 SP1 and the DirectX SDK (November 2008) are not installed, you
will need to download and install the following redistributables:

Visual C++ 9
http://www.microsoft.com/downloads/details.aspx?familyid=A5C84275-3B97-4AB7-A40D
-3802B2AF5FC2&displaylang=en


DirectX November 2008
http://www.microsoft.com/DOWNLOADS/details.aspx?displaylang=en&FamilyID=886acb56
-c91a-4a8e-8bb8-9f20f1244a8e


Intel(R) Threading Building Blocks
----------------------------------

Download a release of TBB from: http://www.threadingbuildingblocks.org/
and copy tbb.dll and tbbmalloc.dll from the download to the same directory containing
FluidRender2D.exe and FluidRender3D.exe.

Simon Carless
19 Jun 2009 at 7:12 am PST
profile image
The password issue is fixed, incidentally, thanks for being patient.

Robert Allen
20 Jun 2009 at 11:23 am PST
profile image
Again I'll ask: why didn't Intel use the POSIX thread model? I'm curious.

Jeff Freeman
22 Jun 2009 at 8:29 am PST
profile image
Robert,

We wanted to highlight a parallel programming approach without the need for a custom thread pool model. Often times such implementations become designed around functional versus task based approaches that otherwise artificially limit (undersubscribe) available CPU cores. The task based approach to parallelization taken here exploits TBB's ability to fully subscribe available CPU cores, taking equal advantage of available CPU horsepower on today's multi-core processors and beyond. TBB is an excellent fit here since it's Cilk-based task stealing approach lets the simulation scale with available CPU cores.

Cheers,
Jeff
Software Engineer/Visual Computing Software Division/Intel


none
 
Comment:
 


Submit Comment