GPU Metaballs

Posted: December 20th, 2008 | 5 Comments »

I've been meaning to implement this idea for ages, it's a GPU implementation of 2D metaballs. It's very simple, very fast and doesn't even require hardware shader support. Seems like the kind of effect that could be useful in some little game..


It's quite fun to play with (use left drag to rotate the emitter), so I might try and fancy it up with some better graphics and collision.

The demo is below, I'll probably release source at some stage but at the moment it's all tied up in my dev framework which needs to be cleaned up (the exe is also larger than it should be as I have all sorts of crap linked in).


The simulation is just done using my simple particle system but it would be fun to implement smoothed particle hydrodynamics..


5 Comments on “GPU Metaballs”

  1. 1 gregory said at 2:13 pm on February 8th, 2009:

    indeed i would fancy looking at the code to understand how it's done

    cool demo

  2. 2 kiplantt said at 8:10 pm on May 11th, 2009:

    I would also be interested in seeing the code or at least some explanation about the process used in this demo.


  3. 3 mmack said at 8:55 pm on May 11th, 2009:

    OK the technique is really really simple. Here are the basic steps:

    1. Set up a particle texture like the one in the demo, so that it's alpha channel represents density falling off from the center (any shape will do, experiment with different falloffs)

    2. Render a whole lot of these to a render target with additive blending, this create's a 'density texture'.

    3. Enable alpha-testing, and blit the density texture to the back buffer. The alpha threshold will affect the 'viscosity' of the fluid.

    Hope that helps :)

  4. 4 Robert S said at 2:13 am on December 24th, 2010:


    Thanks for the demo and the explanation. Do you think your approach can work on OpenGL ES 1.1 devices such as the iPhone or an Android device?


  5. 5 Alice said at 11:12 am on September 7th, 2011:

    That looks great and very fast. Any chance to get a look at the code?
    Good job!

Leave a Reply