Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Fluid Simulation Tests

Discussion in 'Works In Progress - Archive' started by Azial, Mar 18, 2015.

  1. Azial

    Azial

    Joined:
    Mar 19, 2013
    Posts:
    17
    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 https://nerget.com/fluidSim/ 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 http://www.reddit.com/r/Unity3D/comments/2a5h3q/realtime_water_simulation_v2/

    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 http://sourceforge.net/projects/edulb/files/. 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.
     

    Attached Files:

    Last edited: Mar 29, 2015
    Teagarden, tng2903, Torigas and 5 others like this.
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Holy smokes!!! Definitly will try!!!
     
  3. Sykoo

    Sykoo

    Joined:
    Jul 25, 2014
    Posts:
    1,394
    Woaw, this looks incredible!
    Is it OK to use it in commercial projects (like games)?
     
  4. Azial

    Azial

    Joined:
    Mar 19, 2013
    Posts:
    17
    Yes, feel free to do what ever you want with it ;-)
     
    Sykoo likes this.
  5. unity_sg

    unity_sg

    Joined:
    Sep 14, 2010
    Posts:
    95
    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 ?
     
  6. Azial

    Azial

    Joined:
    Mar 19, 2013
    Posts:
    17
  7. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    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.
     
  8. norby

    norby

    Joined:
    Jul 10, 2006
    Posts:
    277
    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
     
  9. Durins-Bane

    Durins-Bane

    Joined:
    Sep 21, 2012
    Posts:
    175
    I spent about 20 minutes playing with the particles making galaxies! :p Can I get a bigger one?
     
  10. DizzyTornado

    DizzyTornado

    Joined:
    Nov 17, 2013
    Posts:
    134
    Web player doesn't work for me, all there is is a grey band in the middle of the screen... strange...
     
  11. Azial

    Azial

    Joined:
    Mar 19, 2013
    Posts:
    17
    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 :p . 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.
     
    Last edited: Mar 25, 2015
    DizzyTornado likes this.
  12. DizzyTornado

    DizzyTornado

    Joined:
    Nov 17, 2013
    Posts:
    134
    Ok, thx, I downloaded it, but I haven't had a chance to use it. I may use it in my own game.
     
  13. paraself

    paraself

    Joined:
    Jun 30, 2012
    Posts:
    139
    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.
     
  14. Azial

    Azial

    Joined:
    Mar 19, 2013
    Posts:
    17
    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).
     
  15. paraself

    paraself

    Joined:
    Jun 30, 2012
    Posts:
    139
    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.
     
  16. Azial

    Azial

    Joined:
    Mar 19, 2013
    Posts:
    17
    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).
     
  17. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    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.

    http://www.memo.tv/archive/msafluid_for_processing_v1_3