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