a small fluid engine demo/test

Community Forums/Showcase/a small fluid engine demo/test

Nate the Great(Posted 2009) [#1]
hi

I decided to experiment a little with fluid dynamics just to keep my creative juices flowing before I start on my fluid engine so here is a little demo. :) enjoy

Controls:
LMB - create water particles (limit of 1,000)
RMB - attract particles to mouse (use short taps to keep system from getting over entergetic and exploding)
V - show velocity vector and turn off light blended particle mode

DOWNLOAD HERE

screenshot:



---------------------------------------------------------


Wiebo(Posted 2009) [#2]
Behaves cool but doesn't look like a fluid at all. How are you going to solve that?


plash(Posted 2009) [#3]
What Wiebo said.. It doesn't behave much like a fluid.


Nate the Great(Posted 2009) [#4]
@wiebo in what way? It behaves pretty fluidy to me... I do have the 'stickyness' factor pretty high though

This is NOT the engine, just something I threw together completely seperately.

Oh were yall talking about the rendering of it? that is just a bunch of light blended sprites. The rendering is going to be up to the user.


Pongo(Posted 2009) [#5]
For a real fluid feel to things, do some research on Navier-Stokes.

edit: removed example.


plash(Posted 2009) [#6]
Oh were yall talking about the rendering of it? that is just a bunch of light blended sprites. The rendering is going to be up to the user.
Somewhat, but not really what I was referring to.


Nate the Great(Posted 2009) [#7]
ok so whats wrong with it? I really dont understand... and pongo I am going for a position-verlet based not grid based but thanks for that anyway it is certainly very interesting. I have posted on other forums and they really love it and say it is really realistic and all and I just don't get what yall think is wrong with it. Please be more specific about the problems and ill change it, but from watching vids on youtube, it looks like mine is about like a lot of the particle based ones on there although it is not as fast yet.

when I am in velocity vector view mode, I see all the things a fluid actually does, pressure waves, rolling, spirals and vortecies when waves crash, etc... maybe it is my crappy fluid rendering skills that make people on this forum dislike it? I am not attacking anyone, I just dont get why this post was so negative... how about a fresh start on this...

so what exactly doesnt look realistic about how the fluid acts? I am not talking about the rendering. here


Yasha(Posted 2009) [#8]
There's not enough surface tension. It explodes far too readily - particles seemed to fly straight apart when colliding, and don't look like they stick together unless they have to. I don't know anything about whether this is accurate behaviour, but it doesn't look accurate. Probably if there were more, smaller, particles, the model would be correct, but the big particles make the apparent lack of surface tension stand out. It also looks like the particles move through each other or at least are able to move straight through large masses without being stopped - I would have thought there should be some kind of interaction with the surface?


Nate the Great(Posted 2009) [#9]
ok thanks Yasha. I'll try to add a bit of surface tension


plash(Posted 2009) [#10]
Probably if there were more, smaller, particles, the model would be correct, but the big particles make the apparent lack of surface tension stand out.
Aye. The particle image used in the demo kind of cloud the feel of it.

Once you get that small it really needs to have some sort of render-merging to make it look like a proper liquid. I would also note that it doesn't seem like the fluid groups together - or even tries.

This is a prime example:
http://www.youtube.com/watch?v=9EbsMtEv2CE


Nate the Great(Posted 2009) [#11]
Aye. The particle image used in the demo kind of cloud the feel of it.

Once you get that small it really needs to have some sort of render-merging to make it look like a proper liquid. I would also note that it doesn't seem like the fluid groups together - or even tries.




thanks. yeah I just thought that was the best image... I have no idea how to do any other type of rendering and I just increased the surface tension and it sticks together now very well I might add, but it makes it a bit less stable.. ill try to mess around with the attraction/repulsion settings.. maybe I should have 2 different types of fluid to demonstrate some of the surface tension that is hard to see in this demo? anyway this has a long way to go so thanks for the constructive criticism

That youtube vid is amazing but they must be using GPU acceleration which blitz max can't do unfortunately... can it?

It also looks like the particles move through each other or at least are able to move straight through large masses without being stopped - I would have thought there should be some kind of interaction with the surface?



this test is based solely on particles, and is not surface-based so if a particle is moving too fast, it will go straight over a few particles and end up on the wrong side of the next, accelerating it.. so just don't have high speed water in a game? lol but I see what your saying and it is a problem with any particle-based fluids moving at high speeds


plash(Posted 2009) [#12]
That youtube vid is amazing but they must be using GPU acceleration which blitz max can't do unfortunately... can it?
Anything is possible - if any C based language can do it, Max certainly can (but don't expect it to be easy).

I believe the game in the video is for the PS3.


Nate the Great(Posted 2009) [#13]
hmm maybe ill post in the blitz max section about GPU acceleration... maybe it is built in to the threading?

that reminds me! I need to get around to threading this!


plash(Posted 2009) [#14]
hmm maybe ill post in the blitz max section about GPU acceleration... maybe it is built in to the threading?
I doubt that.


Pongo(Posted 2009) [#15]
Don't be too put off by the criticism,... it's just that it still needs to have some stuff done before it will start to look convincing.

Here are a few things I would suggest.
- It's all really "floaty". This may be a personal thing, but almost all physics engines seem to operate in low gravity, and this certainly does that as well.

- The rendering of the particles isn't working in that it is all soft and mushy. You may want to run a threshold filter over everything so that you get a metaballs feel to everything. That will help hold things together a bit better and shapes will appear to absorb into each other better.

- More particles, smaller particles. Obviously you'll run out of CPU at some point, but it needs more IMO.


Nate the Great(Posted 2009) [#16]
Don't be too put off by the criticism,... it's just that it still needs to have some stuff done before it will start to look convincing.



I tried to imply that it is far from complete. I guess I wasnt successful. :)

about the floatyness. well if that seems to be the case for all physics engines, I dont see a problem. :) I think its because high gravity in a physics environment tends to be hard to deal with, ie particles get too much energy from too hard a fall and go through everything in the scene

for the second dash - I dont know how to make a threshold filter... ill google it but from one or two I have seen, they look nice but can be really slow for such a big screen size


I definitely agree more particles and smaller particles but I have run out of cpu cuz my cpu right now is really slow and 1000 is all it can handle.

again thanks for the suggestions


Pongo(Posted 2009) [#17]
By threshold, I simply mean to check the pixel values if they are above/below a value, and use that to generate a new image. Example in this thread. http://www.blitzbasic.com/Community/posts.php?topic=79767#895707

As for the physics being wrong and acceptable because everyone is doing it,... let me step on a soap box for a second here.

Why? ,... why accept something that does not look right when you have the power to fix it? Following along with the floaty stuff makes you the same as everyone else, including a ton of large developers. The thing is though, it's still wrong. If you take the extra time to get it right, it will stand out as being correct in a sea of mediocre simulations.

I don't mean to be all preachy here, I'm just trying to get you to push yourself harder. You say that 1000 particles is all you can do, but I challenge you to find out why it is that low. Is it the draw-time? In that case, calculate more particles, but come up with a more efficient way of displaying them. Is it the physics calculations? Try better algorithms that don't have to calculate as much.

When I first built my particle engine, I was getting slowdowns at around 500 particles, but after re-coding to a single-surface system, I was able to move up to about 20,000 particles with the same performance. That's a huge increase in performance for very little work. If I would have settled with the 500 particles, I would have been selling my game short by a large margin.


Nate the Great(Posted 2009) [#18]
pongo I was just kidding about not seeing a problem. it was sarcasm! ahh the downfall of forums as opposed to real life. of course I plan to make better gravity

I really love this project I am working with though and it is made in bmax so I dont think I can do that single surface stuff but I will still look into optimizing stuff.

how on earth did you get 20,000 particles in blitz 3d!?! (rhetorical question) edit: was this a physics engine or just a particle system?

I am multithreading it right now and seeing pretty nice although minor increases in speed. maybe if I can harness the GPU by interfacing with c?

thanks for the link! I remember that conversation now! it was sooo long ago though I had forgotten, but I'll have to experiment with it's speed for a while before I can know if it is fast enough to use.


Nate the Great(Posted 2009) [#19]
ok so I racked it up almost double! to 1800! on a dual core.. anyone have a quad core to test it on? and I forgot to implement a shifted grid too.. oops.. maybe once I do that, I can get ~4000 :) I have still yet to try using some kind of threshold renderer.. I may upload it tomorrow


Pongo(Posted 2009) [#20]
Ahh,... well in that case you forgot the :)

20,000 particles,... just dumb particles,... no physics on those, but I was able to transform (rotate/scale/move) each individually and maintain framerate. They were also drawn quite small on the screen to achieve this, but it was really a stress test only. As they got larger, fill rate issues begin to cause trouble. Real game use rarely exceeded 4-5000 particles at any one time.

Anyways, the point was that optimizations can go pretty far with some of this stuff. If you are limited to 1000 physics particles, then I would try to have those particles drive the motion of "dumb" particles.

And yea, the threshold thing is pretty slow. I don't use BMax, but I would guess it's faster than b3d for that though.


Nate the Great(Posted 2009) [#21]
I was gunna say if you got 20,000 physics particles thats simply unbelievable! 20,000 dumb particles is still quite an accomplishment. I never had a use for that many so I never single surfaced any of my particle systems... come to think of it, I probably should go back and do that. :) later

What do you mean they drive the motion of dumb particles?

and rendering is the least of my worries... perhaps I will leave it out of further demos to prevent dissapointment? lol


Pongo(Posted 2009) [#22]
What I mean by "smart" or "dumb" particles is this.

The smart ones have a full physics applied to them, the dumb ones simply grab the calculated values from a nearby smart one and go with the flow. It's just a way to cut down actual calculations.

I would probably try to do this by setting up an array of vectors, as big (detailed) as I could get away with. Then I would just have the particles refer to the vector field to figure out how they should move.


Nate the Great(Posted 2009) [#23]
oh I see.. so you are talking about a grid-particle hybrid? nice idea ill have to test it... I think GPU acceleration will be enough that optimizations like that will have no effect but GPU acceleration isnt cross platform so I'm not sure about using it for the final engine. I'll definitely give your idea a try. perhaps I could have two arrays.. one for smart and one for dumb.. and they would alternate every frame?


plash(Posted 2009) [#24]
I think GPU acceleration will be enough that optimizations like that will have no effect
Keep in mind that you probably can't just use Cuda, OpenCL or such right out of the box - it may only work on certain cards.


Nate the Great(Posted 2009) [#25]
Keep in mind that you probably can't just use Cuda, OpenCL or such right out of the box - it may only work on certain cards.



keep reading after where you quoted me

but GPU acceleration isnt cross platform so I'm not sure about using it for the final engine


so I will try it out but its not likely that it will work out, in fact I just found out Cuda doesnt work on my machine so I'll just leave GPU acceleration alone for now


plash(Posted 2009) [#26]
keep reading after where you quoted me
You did not say anything about using the GPU for calculations might not work pertaining to a particular card, but only that it is not cross-platform.


Xzider(Posted 2009) [#27]
Cool effect.

Remind me of a flood fill game made in flash...Anyone have a link to one?


Nate the Great(Posted 2009) [#28]
thanks xzider

@plash - ok well I guess I wasnt being clear enough. I wont use GPU because its not cross platform and it depends on the GPU