Solid water simulation (buoyancy + water surface)

Hi,
I wonder how to simulate water more simpler than with particle-based approach discussed here:
http://box2d.org/forum/viewtopic.php?f=3&t=574

I was thinking about some combination of buoyancy controller and dynamic water surface made of linked segments.
Something like presented here would be just great: http://www.youtube.com/watch?v=ytrA7MVMndQ
Of course there are other issues: communicating vessels problem, overall fluid capacity, etc.
Any ideas?

Thanks,
Mirek

PS. Sorry, I decided to post in new topic, because the existing one rather talks about fluid particles.
I'm curious about this as well. I'm guessing it's possible to find papers modeling water with height fields.

And after a quick bit of searching, it looks like the relevant paper is
Kass, Michael, and Gavin Miller, "Rapid, Stable Fluid Dynamics for Computer Graphics," SIGGRAPH, 1990, pp. 49-55

I can't find free access to the paper online, but Noe and Trier have a paper for the gpu version and it looks to cover the relevant formulas.

http://projects.n-o-e.dk/?page=show&name=GPU%20water%20simulation
I came across good publication - "Real-Time Fluid Dynamics for Games".
It describes physics of fluids and example implementation which uses grids, not particles.
I think this is good example, just has to be simplified for 1D water surface (proposed equations are for 2D).
I also consider additional things, which should be implemented:
- methods of applying proper forces to water while collision with other objects
(all kinds of shapes simplified to bounding spheres?)
- buoyancy force working with grid (different water heights) instead of flat water surface
Having all this coupled together there is a possibility of implementing class like b2BuoyancyController.
One would only have to create water controller and add bodies, like in b2BuoyancyController.
Please advise me, if this is reasonable.
I'm not sure Stam's technique is easily extended to water surfaces. You can try.

I was able to implement the paper I listed without too much trouble, although I did have to correct to maintain constant area (otherwise the errors build up and slowly make the water disappear). It looks just like the video you linked and it's relatively fast. I have something like 25 segments and the algorithm is basically O(n), so it's not too bad. The one tricky thing left is collision detection and response, which I assume aren't terribly hard.
I implemented very simple and fast fluid simulation described in Real Time Fluids in Games.
It works really good and is enough for my purpose.

I improved the algorithm, because the water did not follow the calm surface level (CALM):

Code: Select all

float h[N]; // levels of water
float v[N]; // velocities

Update function:
for (int i=1; i<N-1; i++)
{
   v[i] += (h[i-1] + h[i+1] + CALM) / 3.0f - h[i]; // CALM is a height of 'calm surface level'
   v[i] *= 0.991f;
   h[i] += v[i] * dt;
}
// boundary conditions
h[0] = h[1];
h[N-1] = h[N-2];
Do you have a water class/example test bed you'd like to share? I'd like to make a little boat float on some water, but I don't want to use particles.

Hayden
I don't have testbed example for this, it's still under development, I don't have enough time to finish this.
In fact I'm using HGE engine for rendering. It would be hard to draw water in the testbed, as water surface is not an Box2d object. Any ideas for that?
As for the water engine:
- enclosed was only simple algorithm for updating current water heights
- I implemented also buoyancy force which depends on different water levels
- the last problem (not solved yet) is to check collisions of bodies with the water and deform water depending on:
- body shape, mass, velocity, direction (object sinks or emerges)

Original thread: https://box2d.org/forum/viewtopic.php?t=2746