Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How to render metaballs?
I am a Python programmer familiar with the Panda3d and Blender3d APIs. My math kinda sucks, but I know enough to write game logic code and procedural model generation code, as well as importers/exporters for the 3d modeller Blender. So you kind of get my level of experience. So can anyone explain or link to a tutorial which explains what needs to be done, without advanced math or with mentioning what math concepts are needed?

This is what I want to achieve:

http://www.youtube.com/watch?v=dEipENLes10
http://www.dailymotion.com/video/xn3xfn_mercury-meltdown-psp-un-trailer-pour-mercury-meltdown_videogames?search_algo=2

Though with probably more metaballs on screen at the same time.

share|improve this question
4  
Yousa looking fora spicy metaball or a smootha metaball? –  Tim Holt Aug 16 '12 at 23:21
    
"The uploader has not made this video available in your country." That might just be because I'm at work and sometimes our stuff goes through India..., but consider the Indian users. –  Byte56 Aug 16 '12 at 23:45
    
For what it's worth, it's also not available in the US, so the audience is rather severely limited... :P –  Steven Stadnicki Aug 16 '12 at 23:48
    
dailymotion.com/video/… –  user17402 Aug 16 '12 at 23:49
1  
Mercury was definitely using marching cubes to do its rendering (Although when the blobs were the size of a particle we just rendered a sphere). –  Goz Mar 5 '13 at 8:53

2 Answers 2

Unfortunately, 'without advanced math' is a fairly high bar to set for this particular tutorial, because the topic is inherently fairly advanced; metaballs are just a more colloquial way of talking about a particular type of isosurface visualization. The simplest way to conceptualize it may be to imagine taking everything down a dimension; imagine that you're working on a plane (or technically the surface of a sphere) rather than in space, and consider a classic heightmap; then the coastline of the terrain represents one isosurface: it's the set of all the points on the map where the height (the elevation above sea level) is zero. Now, suppose that you had a bunch of elevation data and you were asked to draw coastlines. One approach would be to (somehow) find one spot along a coast and then 'follow that coastline' until you get back to your original point — but that requires you to find that first point, and when you complete your loop you can't be sure whether you've missed anything (imagine tracing the coast of England and entirely missing Ireland in the process).

Instead, you might try an approach where you scan over your map pixel by pixel, looking for spots where you have two adjacent points, one above water and one below, and then carefully drawing a line that cuts between the two, somehow making it match up from pixel to pixel. The generalization of this idea from two to three dimensions is commonly known as the marching cubes method, and it's the most common algorithm for rendering isosurfaces; things are somewhat more complicated in the 3d case than in 2d (since you effectively have 256 cases, one for each of the 28 possible assignments of 'above surface' and 'below surface' to the vertices of a voxel), but the core ideas are the same. Note that even pretty low resolutions on your grid can give good results for this; the demo you linked to is probably running the Marching Cubes algorithm on a 32x32x32 (or likely even 16x16x16) grid and it looks perfectly reasonable doing so.

This leaves open the question of just what your heightfield is, of course — I don't have time to go into that side of things right now (although some searching should find you a handful of different potential functions), but I'll try and flesh this answer out a bit later to give some of the details on that front too.

Of course, because you're essentially dealing with n3 pieces of data (the values on an n x n x n grid) then even fairly low grid resolutions can get expensive pretty fast. With the right potential function, though, you can use interval arithmetic to bound the values of your potential function on larger chunks of space and cut down on the number of actual calculations you have to do; essentially, this is applying octree-style spatial partitioning to the metaball problem.

share|improve this answer

One option is to use Marching Cubes. There are plenty of tutorials and example code in the Internet such as this. Implementing this is not very easy, but doable.

Thanks to the increased power of computers and especially GPUs, raycasting has also become a fast enough solution for rendering metaballs and other surfaces. Check for example this tutorial. This should be easier to implement. The downside is that it might not fit to the rest of the 3D engine as well as polygonizing the metaballs.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.