teichgraf's picture

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. ;-)

Screenshots
Screenshot 1 Screenshot 2 Screenshot 3

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
objarni's picture

Coolness!

Do you use some kind of accelerated structure to avoid O(n^2) physics/collission detection?

teichgraf's picture

Do 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.

Inertia's picture

Quite 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 ;)

Mincus's picture

Looks 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.

teichgraf's picture

Thanks 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.

Inertia's picture

Regarding 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.

Mincus's picture

Yeah, 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).

teichgraf's picture

[...]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.01 or something like this.
And as I also stated in the first post, there are a lot of optimizations, which could be done.

teichgraf's picture

I 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.

Mincus's picture

If 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.