Metaballs 2D       

Metaballs are a well known old-schoold effect. The simplest version is in 2D. That's less impressive than in 3d, but still, it can give beautiful results.

Theory :

A metaball generates a field of potential around its center. For example, the potential function can be 1/d with d the distance between the pixel and the metaball center : 

Then, the sum over the image of the potentials of each metaball is computed. That's called a potential map. To create the resulting image, we need to create a mapping from a potential value to a color value (ie, a palette). That's the most influent step to get nice results.

Eventualy, there are three parameters to tune to get very different results:

Optimization :

For avoiding the computation of distance in the potential function (a square root and several mult), a table of potential is precomputed. It has a size of 256x256 for example. Then to add the effect of a metaball to the potential map, we just add this table on it. With smaller metaballs having size of 128, 64, 32... it is very fast using bits offset to add the tables of different sizes.



Download

download file : metaballs2D.tar ( 10 kb) ( source+makefile Linux)

The .tar file contains the source code and a Linux makefile  (needing openGL and glut)


Screenshots Gallery

   
       
   
       
   
       
     

 

 

 

 

Author :  Adrien Auclair  
adrien.auclair at club-internet.fr
Last update : 16/07/2004