2D dynamic fluid simulation

Hey folks,

Last week I started working on a 2D fluid simulation algorithm and here is the result so far:

https://dl.dropboxusercontent.com/u/9289442/Fluid/Fluid.html

This is an implementation of the Material Point Method (MPM), which is similar to traditional SPH but is faster and way more versatile. With this method, you can have many types of fluids at the same time and they all interact with each other.

The rendering is done by instantiating textured quads, capturing the result in a Render Texture, and applying a shader that transforms the particles in a water-like substance. The simulation can easily go to over 20 000 particles but right now the bottleneck is the rendering. I also made a version with dx11 rendering and was able to reach 20 000 particles with 60 fps.

Future plans:

  • Add viscoelasticity property to fluids.
  • Add support for multiple fluid types.
  • Improve dx9 rendering speed.
  • Multi-thread the simulation algorithm so that it can be used on mobile.
  • Make a dx11 compute shader version of the simulation.
  • Improve the rendering visuals.
  • Allow parameter tweaking in the webplayer.
  • Add complex collision detection.
  • Add buoyancy for Rigidbodies.

Let me know what you think!

Hi,
I like this project!!! The future plans sound great.

I’m a long time fan of the work from Grant Kot so it would be phantastic if there is a comparable solution in Unity.
Would be great to have a CPU Multithreaded version and a GPU accelerated version. And all the tweakable properties to generate different kind of fluids.

I would be very happy if you make such a solution available.

cheers

Thanks for the comment! Grant Kot’s work was my inspiration for this tool. He made some really amazing improvements to his fluid renderer over the years.

Tweakable properties are next on the list :).

we need something like this in the future, and rigid bodies bouancy is a must there:smile: IF u cna make that work u got urself a buyer.

Most of the action will be under water, so it also has to support transparency and gradient, ill keep my eye on this one. There are a few fluid assets out there but i like the way this one behaved alot.

That’s awesome, anyway to share the source ?

Did you put this on the Asset Store or even open source it? Any chance for that?

I’ll look into optimizing it and putting it on github in the future. I looked at the code and it’s pretty awful.