Fluid Simulation

Here's the place to get help and discuss features. The focus is on the C++ version, but generic questions are welcome.
Erin Catto
Site Admin
Posts: 2948
Joined: Thu Sep 06, 2007 12:34 am

Re: Fluid Simulation

Postby Erin Catto » Sat Jun 21, 2008 1:28 pm

I finally took a look at this. Great work Eric! I like how the water surface is smoothly defined.

darkzerox
Posts: 241
Joined: Fri Dec 07, 2007 3:09 pm

Re: Fluid Simulation

Postby darkzerox » Sat Jun 21, 2008 1:58 pm

Looks pretty cool Eric :) Needs some fine tuning like you said, but pretty sweet nonetheless.

ewjordan
Posts: 803
Joined: Sun Sep 23, 2007 2:35 pm

Re: Fluid Simulation

Postby ewjordan » Sat Jun 21, 2008 4:00 pm

Thanks for the encouragement, guys. Yeah, the automatic surface tension is one of the things I like best about this particular method, and it's surprisingly emergent - there's no edge finding or anything like that involved. Unfortunately it's also the main thing I'm concerned about rights-wise, as the method is based on some reverse engineering, and I can't seem to get in touch with the guy that did the original...I'm pretty sure it's a known SPH hack, so I just need to either dig up a reference that explains that or replace it with a more textbook method, and then I'll be a lot more comfortable about releasing this.

Apart from that, there's still quite a bit I need to do, since right now this uses a separate broadphase, which wastes a good deal of processing power, and it's also mapping the fluid physics to a different scale, since stability breaks down due to precision loss at the scale we need it to be at. Also you'll notice that the pressure isn't quite right around Box2d bodies - if you drag something through the water, there's empty space behind it, which is not right. But it's getting there, so hopefully I'll release this soon...

dc443
Posts: 341
Joined: Fri May 16, 2008 10:09 am

Re: Fluid Simulation

Postby dc443 » Sat Jun 21, 2008 5:38 pm

that is very awesome and actually looks like a real liquid, which can't be said for anything I've seen so far that attempted to simulate liquids, other than the Phun liquids (which run like ass). There were fluid effect sims that sorta made smokey swirls, but those don't really count. :P It looks almost exactly like the Gish 2 video, and I'd be willing to bet that the code came from the same source, or at the very least, uses the same exact method.

But yeah, it looks insanely awesome. Like, in a couple years at this rate we'll have very very real looking fluid simulations. How does the performance for this kind of a simulation scale, in terms of the number of particles? I'd be pretty impressed if it was O(n^2) or under..

Oh, and can you make at least one object with a low enough density so that it'll float? I wonder how realistic the buoyancy effects are and how that behavior scales with the particle number/density.

Also, I hate to sound like a nit-picker (cause this is so awesome) but when the bomb object (the circle) is in a corner, and the fluid is being poured over it, it starts to spin counter-clockwise. Also when I tried dragged it into a wall with the mouse joint, the static bodies all disappeared, and it bugged out majorly.

Anyhow, whatever you do, don't abandon this project!!!

ewjordan
Posts: 803
Joined: Sun Sep 23, 2007 2:35 pm

Re: Fluid Simulation

Postby ewjordan » Sat Jun 21, 2008 6:53 pm

Yeah, does look a lot like the Gish demos. Though the source is not Gish, they are probably basing their stuff on similar methods - I should post a link to the demos I based this on, so check out http://kotsoft.googlepages.com/physicsdemos (there's a bunch of other cool stuff there, too, and don't miss his game at http://pollutedplanet.googlepages.com/p ... lanet.html). Also see http://www.fun-motion.com/forums/showthread.php?t=1191, a thread about Polluted Planet. From that thread, it's clear that the method is SPH, so I don't think there should be any rights issues here, as I'm implementing it from scratch (in the demo the only bits that I pulled from that code are the custom broadphase and the SPH kernels, and we aren't ultimately going to use the broadphase anyways, since Box2d already has one).

dc443 wrote:How does the performance for this kind of a simulation scale, in terms of the number of particles? I'd be pretty impressed if it was O(n^2) or under..

Performance of the fluid solver itself is O(N*K) where K is the number of neighbor particles, which should usually be a small constant. The neighbor-finding relies on the broadphase, so once I integrate it with Box2d it should inherit Box2d's broadphase timing (I forget what that is exactly, maybe amortized O(N)?). Definitely less than O(N^2), though.

Oh, and can you make at least one object with a low enough density so that it'll float? I wonder how realistic the buoyancy effects are and how that behavior scales with the particle number/density.

Yeah, at some point I'll put up a demo of this - it's not perfect, because things can get stuck under the surface even if they would otherwise float, but it works okay. This is one area where it would be ideal to have a separate buoyancy solver, so you'd rarely be relying on the SPH stuff for floating.

Also, I hate to sound like a nit-picker (cause this is so awesome) but when the bomb object (the circle) is in a corner, and the fluid is being poured over it, it starts to spin counter-clockwise. Also when I tried dragged it into a wall with the mouse joint, the static bodies all disappeared, and it bugged out majorly.

Yeah, the bugging out is due to a divide by zero that I forgot to check for, my bad. The spinning stuff I still need to track down, I've noticed that as well.

dc443
Posts: 341
Joined: Fri May 16, 2008 10:09 am

Re: Fluid Simulation

Postby dc443 » Sat Jun 21, 2008 7:40 pm

Wow, i've played that game before, but didn't know it was using SPH. I honestly wasn't too impressed with it, though, mostly because it ran so terribly slow, and solid objects were merely really viscous liquids. I really want to see this added to Box2D though!

Amortized linear time? wow. Is this method capable of simulating non-compressible fluids? Since it only goes through a few neighbor particles, it'd be hard to maintain a constant volume.

ewjordan
Posts: 803
Joined: Sun Sep 23, 2007 2:35 pm

Re: Fluid Simulation

Postby ewjordan » Sat Jun 21, 2008 9:34 pm

Nope, one of the big limitations of SPH is that you can't perfectly achieve incompressible fluids, unfortunately. Stability becomes a big issue with large columns of fluid. There are some research papers on limiting compressibility in SPH, and I seem to remember someone having a bit of success with this, maybe after this is in the engine we'll see what we can do about improving things a bit.

dc443
Posts: 341
Joined: Fri May 16, 2008 10:09 am

Re: Fluid Simulation

Postby dc443 » Sat Jun 21, 2008 10:36 pm

In any case, this is leaps and bounds over anything else i've seen, and the fact that you got that many particles going pretty smoothly without very much optimization, and in Java no less, is a very good thing. I always thought that certain mechanics are better in 2-d, and fluids are definitely more useful and fun this way. In fact, it seems to me that the only way to really use fluids in a way that impacts gameplay is in two dimensions.

I dont see the compressability in itself as being much of an issue, but tall columns being unstable, which is a result of that, is a bit of an issue. Perhaps it's possible to do away with the particles after a certain depth, and apply viscous friction to submerged objects. I'm not sure how well this would work with dynamic situations though.

ewjordan
Posts: 803
Joined: Sun Sep 23, 2007 2:35 pm

Re: Fluid Simulation

Postby ewjordan » Sun Jun 22, 2008 1:28 am

The best solution to compressibility, IMO, is what a while earlier in this thread, to implement an automatic transfer between the SPH group and a heightfield water simulation. You always keep a medium thickness layer of SPH particles on top of the heightfield so you get good splashing on the surface and for any water that is flowing, but for pools, you rely primarily on the heightfield simulation. This is straightforward, as methods for heightfield water waves are very easy to implement. The only part that's tricky is coming up with a condition to condense SPH particles into the heightfield and vice versa without artifacts. A low resolution velocity field under the heightfield surface could even preserve things like vortices and flow underneath, which would help realism quite a bit.

That's not a promise that I'll do this myself, though, at least at the moment. :)

Wahooney
Posts: 155
Joined: Tue Sep 18, 2007 6:17 am
Location: Western Cape, South Africa
Contact:

Re: Fluid Simulation

Postby Wahooney » Sun Jun 22, 2008 1:57 am

It's looking really cool, ewjordan :D

Any plans on how one could derive a 2D mesh (purely for rendering purposes) from the particles? Some sort of 2D meta ball method? Voronoi?


Return to “General Discussion”



Who is online

Users browsing this forum: Bing [Bot] and 3 guests