Apr
12
2013

Water Particles

water_particles_unity3d

Converted this javascript demo to Unity C#: Aqualibrium by Gerard Ferrandez

Info:
– Had to make some modifications since all those javascript [this] that.x variables were quite complicated..but seems to work 🙂
– Screenshot shows 500 spheres with debug.drawlines to each neighbour particle (added gravity on by default)

Current version:
– Got distance calculation bit faster (mainloop went from: 192ms for 1500 particles, to: 104ms for 1500 particles) (debug.linedraw is on): using this sphere Distance Between 2 points
– If I use default sphere as prefab for the particle, it doesnt get batched, but default cube does ..Oo?

TODO:
– 3D version?
– Add Blobmesh = water?
– Optimize..if can..
– Different fluidish materials? (mass, friction, break-ability?)
– Sand simulation? (ground digging with excavator..or maybe better using the eulerian water sim grid?)
– Test threading? http://unitygems.com/threads/

Webplayer:
http://unitycoder.com/upload/demos/WaterParticles1/ (500 particles)
http://unitycoder.com/upload/demos/WaterParticles2/ (additive particle shader)

Download source:
waterParticles.unitypackage

Image#2: Testing threading with 1500 cubes.. its fast & kind of works, but some particles wont slown down at all..
unity3d_threading_test(click for full size)

Image#3: Nice idea here..but it would pretty much need unity pro: http://www.patrickmatte.com/stuff/physicsLiquid/
Tried with additive particle shader instead:
water_particles_blue_shader_unity3d(click for full size)

Image#4: Scaling particles based on neighbour count (would be also interesting to stretch them based on speed..)
water_particles_scaled_unity3d(click for full size)


17 Comments + Add Comment

  • Do you have the source code posted?

  • Do you…? D=

  • Its coming up in next couple weeks.. need to fix/clean it up after it went broken with all the threading tests etc 🙂

  • This is seriously epic.. Very genius. 😀 Hope your SC is flexible, as in allowing for particles to be attracted rather than pushed..

  • Very cool result!

    Can you share the source code with us?

    Tks 😀

  • Source added.

  • […] Water Particles « UnityCoder – Unity3D […]

  • 2D dynamic fluid simulation (webplayer demo)
    http://forum.unity3d.com/threads/205291-2D-dynamic-fluid-simulation

  • First of all, thanks for this! Really appreciate it!

    What mesh do I use with this? I opened the file and the SphereParticle did not have a mesh attached with it, so when I clicked play, it did not show anything.

    I’ve tried it with a Sphere particle which doesn’t look right enough and has 700 draw calls because of the routine in the for loop that creates the 700 particles. However when I tried it with the Quad mesh, it resulted in 1 draw call but that doesn’t look enough like water either.

    So what mesh do we use? The mesh options that comes with Unity Free version don’t seem to make it look correctly like the water in the demo web player. What did you use?

    • hmm, might had been a custom quad mesh (from http://wiki.unity3d.com/index.php/CreatePlane ) ** yes, it was: custom mesh from createplane “Plane1x1W1L1HC”

      (and transform scale was 32)

      • Awesome! That worked mgear! Thank You.

        I noticed you showed a better version of water particle based simulation on the Unity forums. I was wondering if you can guide me on what I can do to achieve what you showed on the Unity forums. I don’t need the full source but some guidance on what could be adjusted, the direction and such should be enough.

  • The link is here: http://forum.unity3d.com/threads/205291-2D-dynamic-fluid-simulation

    What did you change specifically to make it more realistic and better colors? A different shader?

    • actually that is not mine 🙂 i saw that while ago also, looks very nice! (but needs unity pro for render textures, readpixels could work but slower..), to me it looks like using this idea or similar: http://www.patrickmatte.com/stuff/physicsLiquid/

      • Ahh nvm. It seems you were able to achieve scaling particles based on neighbour count in Image #4. How did you implement that? Did it change the performance in a bad way?

        • I think it didnt change it much, as it was only doing this:
          // scale by neighbour count
          // float s = Mathf.Clamp(ncount*0.5f, 0.5f,32.0f);
          // this.obj.localScale = new Vector3(s,s,s);

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.