19
\$\begingroup\$

At this point the platform and programming language don't matter I would just like to know if something out there exists for this. Any help is appreciated.

\$\endgroup\$
1
  • \$\begingroup\$ I've implemented a custom 2d fluid engine. I was able to get a working example up using this paper on viscoelastic fluids and the code from Flui°D°emo as a template. However, the fluids are not as stable as I would like and code could use lots of optimization love (multicore processing, cache friendliness, etc). What I want is a library that has done all that already, so that I only have to integrate it with Box2d and my game. \$\endgroup\$
    – deft_code
    Commented May 30, 2011 at 12:43

4 Answers 4

8
\$\begingroup\$

Look into what Q-Games used for Pixeljunk Shooter. It is a 2d game with pretty involved fluid physics. I'm not sure if they used a homegrown or middleware physics engine, but the information is probably out there somewhere.

\$\endgroup\$
1
  • 8
    \$\begingroup\$ They have used a homegrown engine, but have included techniques that can be applied using any physics engine en some custom code. The actually gave a very informative talk about their fluid dynamics at GDC (slides here: gdcvault.com/play/1012447/Go-With-the-Flow-Fluid) \$\endgroup\$
    – ghost
    Commented May 28, 2011 at 8:39
6
\$\begingroup\$

Well i havn't looked into this, but i know for a fact that almost any physics engine can emulate the idea. Box2D, etc.

Basically have particles bouncing around, off surfaces and eachother (faster for gasses) but also give them a constant gravity like effect (liquids would all have the same, but some gases you might want to rise slowly).

If you link up the outer particles you will get a polygonal shape representing the mass

OR

if you simply draw a pixel or particle graphic over each particle, you can achieve a cloud effect for the mass instead.

\$\endgroup\$
7
  • 4
    \$\begingroup\$ This answer is not suited for real time games in a practical size. \$\endgroup\$ Commented May 28, 2011 at 6:32
  • 3
    \$\begingroup\$ I am not sure why you'd say that, as fluid dynamics are very often modelled as particles. For examples see the nvidia tech videos on fluid particles on youtube, the program Algodoo (formerly called Phun) or the talk Q-Games gave about their PixelJunk Shooter game (slides at gdcvault.com/play/1012447/Go-With-the-Flow-Fluid). In the latter case, Q-Games shows how they construct a polygon out of a collection of particles. I would think that this verifies that this answer is quite valid for realtime implementations IMHO. \$\endgroup\$
    – ghost
    Commented May 28, 2011 at 8:45
  • \$\begingroup\$ WOWOW why the downvotes? I'm not raging, just want to know why. It is a realistic technique and is used. \$\endgroup\$
    – Joel
    Commented May 28, 2011 at 10:22
  • \$\begingroup\$ "particles bouncing around, off surfaces and eachother (faster for gasses)" that sounds like you are describing fluids on the molecular level, and while a naive approach could work with baked simulation, it wont work well for real time games. Particles are fine as long type of simulation is correct, "bouncing arround" does seem like it would work with macro particles. You also grossly misrepresented how to simulate density. \$\endgroup\$ Commented May 30, 2011 at 3:54
  • \$\begingroup\$ Particles works good enough en.wikipedia.org/wiki/Smoothed-particle_hydrodynamics. Was used in FLT:s latest demo as described in directtovideo.wordpress.com/2011/05/03/numb-res This implementation might be a bit heavy weight, but simpler approximations as in the Pixel Junk Shooter GDC talk should work fine. \$\endgroup\$
    – void
    Commented May 30, 2011 at 5:52
6
+100
\$\begingroup\$

The only library I could come up with that specifically deals with fluids is Fluidic. It is pretty alpha and only has one release, though. The physics library Bullet supports 'smoothed-particle hydrodynamics', a technique used to model fluids. Although the library is geared towards 3D, you could apply constraints to one axis to make it work in 2D.

My recommendation would be, as I already mentioned in some comments on other answers, to use a standard physics engine like Box2D or Chipmunk and use a number of circles to model the water (with gravity) or gas (without gravity) and combine these together into one water or gas body. You can apply some constraints on the individual bodies to make them 'clump' together so you can simulate viscosity. Have a look at this video to see how the individual bodies (modelled as squares in the video) work together. Note, however, the technique used in this video is not the same as mentioned in this paragraph. You can use the video to get a feel of how the circles interact with each other and try to mimic this with the constraints present in the physics library used.

The interesting part comes when you want combine multiple circles into body of water. The most straightforward solution I can come up with is drawing each circle as a metaball so they appear as part of a larger body. You can find the math and some example code behind these bodies here.

\$\endgroup\$
2
  • \$\begingroup\$ The video you linked to is using much more than just lots of circles. He uses a technique known as SPH. The blaze port of Flui°D°emo uses Box2d to find collisions and apply forces but uses SPH methods calculate forces not Box2d's rigid bodies. \$\endgroup\$
    – deft_code
    Commented May 30, 2011 at 12:35
  • \$\begingroup\$ You are absolutely correct in that regard. The video was meant to be illustrative instead of an implementation example. Thank you for mentioning my mistake and I have updated the answer to prevent further misunderstandings. \$\endgroup\$
    – ghost
    Commented May 31, 2011 at 14:31
3
\$\begingroup\$

It's been a few years since this question was posted, but I came across it while searching, so I thought I'd update it.

Google released LiquidFun (open source) for the Box2D system. It has some limitations, but it's a quick way to get started with liquid, sand, etc particles with pretty decent performance.

https://github.com/google/liquidfun

PixelJunk has a great approach, but it's a private library. They shared an amazing level of details in their talk at GCD 2010.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .