Metaballs are nifty little blobby objects commonly used in 3D modelling to help getting an “organic look” or in demos as a cheap graphical effect.
They basically consist of a simple function which measures the distance of a certain point in space to the center of the metaball and assigns that point a potential. The potential of multiple metaballs add up, i.e. to get the total potential at a point in space, we calculate the metaball function for each metaball in the scene seperately and add up the returned values. This way we get a so-called “scalar field”.
To make things more interesting, we now define a threshold for this scalar field which determines the actual metaball shape. If the potential at a certain point exceeds the threshold, it is inside the metaball volume, and if it doesn’t, it is defined as outside of the metaball volume. Points that have a potential equal to the threshold lie on the surface of the metaball volume; these are the ones we’re interested in to render the metaballs.
It shows that if we choose an appropriate threshold and then render the surface of the metaballs, we can see that metaballs that get close enough begin to “attract” each other and start to merge. What’s useful about this is that even during merging, metaballs always keep a smooth and continuous surface without us having to explicitly model it. This makes it very handy for organic modelling, since organic models (e.g. plants, humans etc.) usually have no sharp edges and just smooth surfaces. This would be very difficult to model per hand.
Rendering the metaballs is a problem in itself, since there is no fast straightforward solution to render a scalar field. Volume raycasting is one possible solution, though it’s usually too hardware extensive for realtime use. In this implementation, I used the Marching Cubes algorithm, which allows the program to convert the surface of the metaballs into a polygonal mesh, which is then rendered using conventional rasterization.
Download the demo (*.exe & code): Metaballs