realtime fluid dynamics

Started by
20 comments, last by grhodes_at_work 17 years, 5 months ago
hi all. for my new project (some kind of virtual guidance system based on the concept of water flow) i need to implement a fluid solver with the following features: * stable * real-time and scalable for big covered fluid areas with reasonable resolution * insertable obstacles * controllable flow (via placeable drains/sinks) * more or less continous flow through the system, so that the dynamic system does not dampen too fast * 2d simulation might be enough, although extension to 3d would be nice i looked through a lot of papers (seems to be a real huge field of research), especially those of Jos Stam. his method/demo works quite fine, although the math is a bit heavy and i don't like the c-style code. somehow i failed at "porting" it to c++ because now the simulation doesn't dampen like the original. a GPU version (i.e. the version in the GPU Gems book) might be worth a shot too. anyhow, the things i am still wondering about are the scalability + performance (cpu- and memoryusage of Stam's version is proportional to the gridresolution), handling of obstacles (not implemented in Stam's version), the controlling of the fluid and the rendering of flow. controlling: seems to be implemented in Nick Foster's paper (in- and outfow gridcells), but i don't know if it really works out with Stam's stable solver. rendering: of course is the hardest part because it is not really defined yet. it should be more abstract/artistic. i don't want real-time caustics and realistic water surface rendering. it should be more of an blueish underwater view. so maybe some volumetric lighting + fog (like in submarine games) would help. i'm also thinking about some simple texture wobbling (like in quake). in many of the demos either ink/dye advection or texture advection is used to visualize the flow but maybe someone has another better idea ... ?! so, hopefully somebody can point me into a proper direction or provide some helpful resources. any help is appreciated. thx!
Advertisement
Just to clarify, you're not interested in rendering the surface of the water, just underneath the water?
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)
yes. i don't want to render realistic reflections on the water surface (like in the most shader tutorials out there). it would be cool though to have some sort of underwater caustics (light beams coming through the surface) ...

i think that it is important that you see the dynamic behavior of the fluid, but i'm not sure how to visualize that.
I think an interesting effect would be seeing dust, sand, and other debris moving through the beams of light (be it sunlight or lamp). Fluid dynamics is a somewhat intensive problem to approach just for the visual effect of light scattering through the surface of the water. I would use a plasma style light map with a varying periodicity for that. As far as how the water moves beneath the surface, it may be helpful to break the water into cells of pressure and temperature. The temperature would affect the pressure of the cell, while imparting heat to adjacent cells. The pressure of a cell would exert force on adjacent cells and affect the rate at which the cell can take on heat. I've used this method before for wind, and it works quite nicely.
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)
The first thing that popped into mind when I saw your list of must-haves was "Stable Fluids" by Jos Stam. :)

Stam's paper Real-Time Fluid Dynamics for Games is a much better paper to read in order to really see how the math behind it works. Any elementary Linear Algebra book should also cover the topic of relaxation, and would be worth a look.

Fast Fluid Dynamics Simulation on the GPU by Mark Harris (GPU Gems), and Flow Simulation with Complex Boundaries by Wei Le, Zhe Fan, Xiaoming Wei and Arie Kaufman (GPU Gems 2) are also really good papers for understanding the math.

Altogether, I think that pretty much covers your list.

As for emitters and drains, simply increase or decrease a cell's fluid amount after the entire timestep. The rest will happen automatically.

For the boundaries, it's similar to the boundary cells of Stam's paper, except that one must consider that the surface normal may not (most likely will not) be perpendicular to the grid. To calculate the surface normal, you just check all neighbouring cells to see if they're boundary cells too. Then when it comes time to reflect the fluid, you don't perform the simple fudge of reversing the fluid's velocity vector, but compute the reflection based on two vectors like in the real world.
thx erissian, your approach sounds interesting. got any screenies and or resources of the plasma style light map thing?

just to clarify: the fluid dynamics simulation is not for the rendering - there are animals swimming inside the flow and they are affected by the flow (so i use the velocity field of the flow).
but i want to visualize the movement of the flow too, somehow. because otherwise spots without animals would look stale and boring.
To visualize the flow direction, you could render a small cone in each cell, aligning its pointy end with the direction component of the fluid's velocity vector. You can also set the RGB colour of the cone to the same values as the XYZ component of the fluid velocity vector, giving you another level of visual clarification.

As for the speed component, you can always scale the cone accordingly.

Advanced Graphics Programming with OpenGL by McReynolds and Blythe details several other methods of flow visualization, from field lines to streamlines, to ... you name it, it's in there.
as for visualizing the flowfield: id suggest spawning air bubbles at low pressure areas of the fluid, which should give a fairly realistic effect.
I dont know if you have seen my videos yet but i have written a small Real time fluid solver myself.

http://video.google.de/videosearch?q=fluid+solver
http://www.gamedev.net/community/forums/topic.asp?topic_id=422299

I think that grid based approaches are too slow to be interesting.
Also Jos Stems approach is just for non compressable fluids so its quite uninteresting for water.

Extracting the surface is quite tricky though this is what i am working on atm.

My approach is quite stable though.
Its real time.
Obstacles arent much of a problem to add.
The approach is continous.

If i dont write an article about all this i might release the stuff.
@taby: thanks for your help.
actually i did start from stam's "stable fluids" paper and his "Real-Time Fluid Dynamics for Games" GDC2003 talk. and i'm still working on my own glsl-version of the mentioned gpu gems 1 example from harris (although i think his mathematically explainatons are far more complicated than stam's).
thanks for the hint to the gpu gems 2 chapter from wei li et al. i'll definitely look into that.

concerning your rendering suggestions i have to say that i don't want to render it like in scientific visualizations. i already have that (cones, arrows, lines, particles) for debugging and testing purposes. i want to visualize the movement inside the water (the flow), but it should still look like stylized water. maybe just lighting and distorting a nice blue seaground-texture is enough, maybe not...

This topic is closed to new replies.

Advertisement