This project has moved and is read-only. For the latest updates, please go here.

Implementing a basic fluid like water

Jul 27, 2012 at 5:24 AM

Does Farseer provide any sample implementations of this? I see we have something for wind which is nice - but I don't see anything for water. Are we on our own to implement a SPH like algorithm? I fear this may be slow on a mobile platform.. advice on what to do?

Jul 27, 2012 at 9:44 PM
Edited Jul 28, 2012 at 10:33 AM

What's basic about fluid dynamics even if it's just water? :)

Farseer 2 had some water-related stuff that was pretty cool. The only thing that remains now is the buoyancy controller but older code could be ported in theory with good knowledge of the engine.

JBox2D has a simple SPH-ish implementation (recently ported to Box2D) - LiquidDemo. Performance is... what it is.

There are some great open source implementations of SPH fluids around like FLUIDS v2. It runs on the GPU.

It will be extremely difficult to obtain two-way interactions with the rigid body solver, though. Recently there was an attempt to integrate FLUIDS in Bullet. Only one way interaction is available at the moment - i.e. rigid bodies can serve as boundary conditions.

PhysX has fluids with two-way interaction. It doesn't work on mobile and probably won't any time soon. Fluids are very computationally expensive.

Fluids can also be faked by using a lot of small spheres (particles) with zero friction. This could work in some simple scenarios combined with appropriate rendering tricks and as a bonus no changes to the engine are needed. Performance will depend on the number of particles. Something like that:


[EDIT] One of the few games having fluids and using Box2D with some explanation and lots of tricks

Jul 28, 2012 at 4:55 PM

I was looking for something like this:


The author gave me the following excerpt back:

  For the wind, I used this: 
For more info, look up "Stam fluid solver".  Here is as good article:



"Not quite; I just had every physics body in Farseer check with the fluid grid each update to see what new velocity to apply to it.  I just figured out what cell in the fluid grid the physics body would correspond to, and grabbed the velocity data from that cell.  I then used Farseer to add a force with that velocity to that physics body."

 I do have access to the code for the Fluid Solver then - it's just a matter of whether is produces optimal performance results.. 

Jul 28, 2012 at 6:48 PM

You could have a look at Vessel from StrangeLoopGames. Here's where they talk about how their engine came to be:

Particle physics can be very powerful. Here's an example of a work in progress which has fluids. Unfortunately no source yet:

On my PC gemini's testbed has great performance (I don't know if it runs on the CPU or GPU) but if you create a lot of fluid it slows down so I suppose mobiles will suffer.

Jul 28, 2012 at 9:00 PM

Right, I saw 'Gemini' but that's still pretty pre-mature and I can't afford to just wait around. =) So I might try and implement SPH and take a look at Vessel - of course then it comes down to creating a proper GPU implentation I imagine to get an acceptable performance metric.

Although, I don't really need fluids onscreen 24/7; and they're only displayed for a few moments. I might be able to get away with something cheap.. hopefully. I guess no 'quick and dirty' solutions exist.