Flui°D°emo - A 2D Fluid Simulation
Description
Flui°D°emo is an interactive 2D physically based fluid simulation using a Smoothed Particle Hydrodynamics (SPH) approach as described in the paper "Particle-Based Fluid Simulation for Interactive Applications" by M. Müller et al., which utilizes the Navier-Stokes equation and SPH to simulate the behaviour of the fluid. The resulting differential equation is solved with a numerical integration (basic verlet).
The whole project is written in C# 3.0 against the .Net Runtime 2.0.
The visualization and input handling is done with OpenTK - what else. ;-) (GameWindow)
As a by product a little framework for a flexible 2D particle systems, including emitters, consumers and a renderer for Meta-Balls (Blobs) was developed. The Meta-Balls are drawn with a Render-To-Texture (RTT) technique using the framebuffer extension (FBO), if available, a procedural generated gaussian distribution texture and alpha-testing.
The collision handling is done with the Separating-Axis-Theorem (SAT) and Object Bounded Boxes (OBBs).
I released the project as open-source under the GPLv3 license.
By the way, most of the people know Lutz Roeders Reflector, so a .Net binary innately comes with the sources. ;-)
Video
You can also watch a video at YouTube.
Download
Download the Zip here (1594 KB)
The download includes the binaries and the source code (including Visual C# Express 2008 solution).
See "bin\Readme.txt" for further instructions and requirements.
Enhancements
There are a lot of enhancements, which could be implemented.
Currently the whole geometry is drawn in intermediate mode, because it's simple and the framerate for this version is OK. But for sure it would be better to use VBOs.
Another point is the Meta-Ball renderer and the RTT with alpa-test, which would be nicer implemented with a shader.
...
Ideas wanted
My first goal was to build a game using the fluid simulation. And I already have some ideas for a game, but I didn't find an idea that took off.
So, when you have some ideas for a game or other suggestions, reviews, comments, questions, ... don't hesitate to post a comment.







Comments
Apr 09
09:07:22Re: Flui°D°emo - A 2D Fluid Simulation
posted by objarniCoolness!
Do you use some kind of accelerated structure to avoid O(n^2) physics/collission detection?
Apr 09
09:56:21Re: Flui°D°emo - A 2D Fluid Simulation
posted by teichgrafDo you use some kind of accelerated structure to avoid O(n^2) physics/collission detection?
I know, a broad phase collision check with quadtrees or other techniques would speed up the collision test, but actually there was no need for this. The used SAT method is really fast and was sufficient.
The curent collision resolving is done in 2 steps:
1. The boxes (OBBs) are tested against each other and separated, if necessary.
2. The particles are tested against each box. If necessary an elastic collision is applied.
Apr 09
10:24:00Re: Flui°D°emo - A 2D Fluid Simulation
posted by InertiaQuite fun to play around with, good job :)
Not sure where you want to take this, some kind of "Archeologist pulled the wrong lever and triggered a trap, now the cave is flooding" motivated type of 2D platform game might be an option. Another option could be a puzzle game that gives the player pipes/hoses/etc. to reroute the fluid from start -> goal without spilling more than 50% of the fluid or something like that ;)
Apr 09
16:23:03Re: Flui°D°emo - A 2D Fluid Simulation
posted by MincusLooks damn cool. :o)
If you're looking for game ideas there was a game involving water simulation, guiding it from the top of a level to the bottomcalled Cataclysm.
Youtube video. Good fun game.
An alternative could be to add some more physics objects and create something like Armadillo Run.
Apr 10
06:46:10Re: Flui°D°emo - A 2D Fluid Simulation
posted by teichgrafThanks for the ideas so far.
I like the one with the puzzle game from Intertia and the Cataclysm game. It's always amazing to see what some guys did in the past. I'm not sure, but maybe I'll do a simple remake of this game, nowadays with a real water simulation.
Apr 10
11:02:00Re: Flui°D°emo - A 2D Fluid Simulation
posted by InertiaRegarding the puzzle game, it should probably be mentioned that it implied 2 phases:
First: setup flow control with some given building blocks.
Second: water simulation.
The simulation only runs with ~250fps at 500 particles on an AMD X2 6400, and by separating the interactive part from the simulation part, you can actually precalculate the simulation and just play it back in 2. so it will run smoothly on pretty much any CPU.
That Cataclysm video looked interesting, the idea to place springs which require a certain pressure from the water before they move is pretty cool. But I wonder where's the challenge in that game? The little jetpack-dude can obviously not drown - he can actually "push" the water with his body - and can place "blocks" to change the intended drain's storage. Is the only difficulty not to release too much water at once? I imagine it's pretty hard to lose that game if you spend the "blocks" to increase the drain's storage room, so it cannot be overfilled.
Apr 10
11:38:16Re: Flui°D°emo - A 2D Fluid Simulation
posted by MincusYeah, only the first 2 levels are shown in the video.
As you get further into it you get "red" water that kills you and aliens that fly around shooting at you. Also there's a time limit on each level (the red bar on the left).
There's also doors with buttons that need opening/closing at particular times and lasers on walls (although I forget what sets these off, been a long while since I've played it).
Apr 11
07:31:36Re: Flui°D°emo - A 2D Fluid Simulation
posted by teichgraf[...]The simulation only runs with ~250fps at 500 particles on an AMD X2 6400[...]
So whats wrong with this framerate? Don't forget, a real fluid physics simulation is performed.
It's not just
particle.Position.Y -= 0.01or something like this.And as I also stated in the first post, there are a lot of optimizations, which could be done.
Apr 11
07:35:42Re: Flui°D°emo - A 2D Fluid Simulation
posted by teichgrafI have changed some code design and fixed minor failures, which were found using FxCop (see Post). I also included the FxCop project file in the sources.
The download was updated.
Apr 11
16:49:39Re: Flui°D°emo - A 2D Fluid Simulation
posted by MincusIf you want a look at the later levels of Cataclysm, I've found my copy and can make some videos if you want.
It was a commercial game that ran on RISC OS (which is a largely dead platform now) which can be emulated but involves grabbing semi-legal ROM images etc otherwise I'd offer you the game itself.
As to the lasers: it appears they're motion sensitive, they go off when you move in front of them, if you don't get out of the way quickly, you die.
There's also ways to "gain" more blocks since you have a limited amount (bottom left in the video).
If you want any more information on it, just ask.
Edit: An additional gameplay mechanic I found whilst playing is "mixing" the liquid.
For example on one level there's blue and yellow liquid. If you let blue in your time increases, if you let yellow in, your time increases, but if you let the liquids mix, you get green and that is what you have to guide to the spout.
Apr 11
08:46:00Re: Flui°D°emo - A 2D Fluid Simulation
posted by Inertia[...]The simulation only runs with ~250fps at 500 particles on an AMD X2 6400[...]
No critique there, just stating the fact that 500 particles aren't much, and the objects in a game (both: particles and the world) will have to be smaller and in higher quantity.
Yes, I've read about the possible optimizations, but the performance gain is pure theory atm and cannot be measured. You might not want to have DirectX 10 hardware requirements for a 2D game to play smoothly, thus the suggestion to have the simulation separated from the interactive part. Something like a specialized version of the Incredible Machine.
Edit: Mhmmm I didn't mean to discourage you to try a Cataclysm style game, it was more intended to be a warning that it will be *hard* to do this in realtime and might not meet your expectations. In your demo the physics are most likely the bottleneck and not the immediate mode calls, so the switch to VBO will not improve framerate times 100.
...or has the discussion ended because I got everyone hooked on Incredible machine? ;)