Fluid Simulation Tests

Hi,

I’m currently experimenting with some fluid or liquid simulations. Import the unity package, open the scene and click and/or drag with the mouse to see funny stuff.

Webplayer: https://googledrive.com/host/0Bzz7Q3iseZxEZGZxUnA2b1dvT0k

There are different models for the liquid e.g. Navier Stokes, Shallow Water, Lattice Boltzmann,… As with every model, they are mathematical abstractions to the real world liquid, optimized on certain aspects like performance and different behaviours.

FluidSim.cs contains a navier-stokes solver based on Oliver's simple fluid dynamics simulator respectively http://www.dgp.toronto.edu/people/stam/reality/Research/pdf/GDC03.pdf. Left or right click to add/subtract pressure and drag to create velocity.

LiquidRipples.cs is a very basic wave generator. Click and drag to add forces to the surface. You will see something like the water effect in World of Warcraft on ultra settings (use the texture as refraction for some shader). I wrote this inspired by Reddit - Dive into anything

LiquidFlow.cs is entirely made up by me and models the water as an heightmap that diffuses based on obstacles and terrain data.

LatticeBoltzmann.cs is based from EduLB - Browse Files at SourceForge.net. Right now, I just converted the algorithm to C#. I need to investigate the “Boundary” method to construct other setups (now its just an inlet from the left and outlet on the right). Click to add particles that flow with the velocity field.

Btw. you can use the output not only on a texture, but as y values of a mesh, making it 3D.

2026449–132734–FluidTests.unitypackage (196 KB)

8 Likes

Holy smokes!!! Definitly will try!!!

Woaw, this looks incredible!
Is it OK to use it in commercial projects (like games)?

Yes, feel free to do what ever you want with it :wink:

1 Like

Hi, the video looks really great !
I’ve tried to import the package in Unity 4.6.2 but the scene looks empty.
Wich version of Unity did you use ?

I’m using Unity v5, so there might be a problem.

I uploaded a webplayer demo: https://googledrive.com/host/0Bzz7Q3iseZxEZGZxUnA2b1dvT0k

I particularly liked the Navier Strokes piece of the demo. This would make for some very cool 2D Smoke effects. I could see something like a gem matching (or other type of game) with an animated background responding to user input on the game board.

Hi Azial

Was the video you posted last week all made within unity ? If yes i have to say that it was really impressive.
It looked like the top fluid engines like Bitfrost and Reaflow but then in realtime .
Great work

Norby

I spent about 20 minutes playing with the particles making galaxies! :stuck_out_tongue: Can I get a bigger one?

Web player doesn’t work for me, all there is is a grey band in the middle of the screen… strange…

I use Unity v5. Maybe you need to update the webplayer? Oh, and in most of the simulations, you have to left- oder right click and drag with the mouse to see funny stuff.

No, the video i postet was a reference. I wrote that I would like to achieve something like that in regards to the ground heightmap. I deleted the link because people tended to just read the headline and see the video :stuck_out_tongue: . Sorry, if i confused you.

If you understand the code in my project package, you might extend it to work like in the video. Btw, in the video, they used a method called “level set” to remesh the data which is stored in the (invisible Eulerian) grid.

1 Like

Ok, thx, I downloaded it, but I haven’t had a chance to use it. I may use it in my own game.

Interesting Topic!
I started to research about fluid simulation in Unity for my fluid dynamics-physics based game, I shifted from Jos’s NS solution to LBM, which have better support for parallel processing and boundary processing. I’ve made it as an separable fluid editor, check out this video.

Your approach sound interesting as Jos’s algorithm is indeed not so good performance wise. In one simulation step you have to go a lot in and out of loops.

May I ask you where you find a well explained reference for the implementation of LBM? I wonder what the FPS would be compared to Jos’s / my implementation in a grid like 256 x 64 (my current setting).

Check out this paper:
http://www.diva-portal.org/smash/get/diva2:566322/FULLTEXT01.pdf

or wikipedia:
http://en.wikipedia.org/wiki/Lattice_Boltzmann_methods

Actually I did not dive too much into the math, my solver is started from this one: Educational Lattice Boltazman
http://sourceforge.net/projects/edulb/files/

As for Jos’s stable fluid, I guess I’ve seen a unity plugin that has done a impressive work on this topic:
https://www.assetstore.unity3d.com/en/#!/content/5717
It’s implemented both on CPU and GPU,

As for performance comparison, I do not have sufficient data to draw a conclusion…yet as far as I know, if its running multi-threaded or on GPU, there should not have big problems. My currently sim grid is 100 * 150, it’s multi-threaded, around 5 ms is spent in Fluid solver update during each frame.

Hope this helps.

Thx, I found a nice LBM code on the web and implemented it in my project (see webplayer and updated package). Its about 1.7 x faster than Navier Stokes (running both not parallel or on GPU).

If you want to start experimenting with GPU versions in Unity without having to buy anything off the asset store, this is a good starting point:

2D: http://scrawkblog.com/2013/05/21/gpu-gems-to-unity-2d-fluid-simulation/

3D (DX11 only) : http://scrawkblog.com/2014/01/09/gpu-gems-to-unity-3d-fluid-simulation/

As for CPU-based 2D stuff, the first one I ever tried in Unity was a fairly simple Java to C# conversion I did of the following which was designed for Processing. I don’t know if I still have the version I made but I’ll have a look this week.