Not logged in, Join Here! or Log In Below:  
News Articles Search    

Submitted by Brian Washburn, posted on April 06, 2002

Image Description, by Brian Washburn

This IOTD demonstrates my 2d metaball engine I wrote in a couple days, rendered in OpenGL.

Rendering and calculating metaballs are very cpu extensive, 2d or 3d. My goal was to have many metaballs on the screen at once without slowdown, so I opted for 2d. To reduce the computing load and increase fps, the window itself is rendered in 320x240, and then is broken into 160x120 chunks. Even then, rendering a mere 10 metaballs would mean 192000 illiterations! (120x160x10). With certain optimizations I managed to reduce that number to around 15000.

Drawing the metaballs involves density/electrical fields. Density fields are usually used to display things such as air pressure or temperature but they can be used to display blobs also. Every point on my 160x120 graph is tested to see how far away it is from all the metaball's centers. If that value passes a certain threshhold the pixel passes, and is rendered. Surprisingly, the color of each pixel is determined almost the same way.


The 'A' key adds a metaball. The 'S' key subtracts a metaball. 'Enter' singles out a a certain threshhold value, and only draws it. (torus)

The demo is available for download here: (41k)

Brian Washburn, 2002

Image of the Day Gallery


Message Center / Reader Comments: ( To Participate in the Discussion, Join the Community )
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

April 06, 2002, 09:39 PM

Polygonization of scalar fields.

Des Browne

April 06, 2002, 10:12 PM

Shut the hell up, I'm sick of seeing this posted postalrat! Work it out your self or take up garderning.


April 06, 2002, 10:33 PM

Actually, you can render your 2D metaballs at über high res with a high framerate AND correctly completely on the 3d card.

You can implement this by either using a texture or using a shading technique to calculate 2d distance.

You simply use this 2d distance calc on the card and render to texture (you can do many in one pass using multitexture AND you can do multiple passes using an additive blend).

Then simply render the texture on a big quad using alpha testing.

Walla, hi-res metaballs. My favourite super hack technique :)

Note - for some reason, copying alpha doesn't work using glCopyTexture on some nVidia drivers.


April 06, 2002, 11:18 PM

These sticky blobs (Meat Balls) are nice. It would also make a good screen saver too as it's not too complicated to look at, but interesting to watch. I like the loose pixel effect too.

I vote to name the < I posted first > people, IOTD Groupies. Always following the show, have no idea what it's about but have to be first in line and believe 'C' is a small ocean.


April 07, 2002, 12:02 AM

No kidding.
DSA- shut up.
You don`t say spit worth reading.

Regarding the iotd;
It looks kinda cool.
The grid background does not add to it tho...
Don`t know about demo- would get a few spf on my pc anyway :(

Whoever did that 3d metaball reflectivity thing did a good job.

Warren Marshall

April 07, 2002, 12:33 AM

Congratulations! You're officially stupid ...

Warren Marshall

April 07, 2002, 12:35 AM

Kurt has taken the comments section away before and I don't doubt he'll do it again. Please don't fuck it up for everyone else.


April 07, 2002, 01:28 AM

and like your metabals, my balls itch.


April 07, 2002, 03:08 AM

I hope Kurt will clean this mess.
Or nobody (except masochists) would want to publish IOTDs anymore.


April 07, 2002, 04:08 AM

wow. (to the 256 byte demo.)
That really puts things in perspective.

I see a lot of people post things like "cool, awsemoe job man" for demos that really aren't that amazing; it gets old rather quickly. I'm not saying we should bash all of the crappy (read as: "not so awesome") demos, but don't say it's awesome, new, optimized, or innovative unless it really is...

I love optimized code.


April 07, 2002, 06:10 AM

Dude, I don't know shit about metaballs, but I happen to know a bit about french and that sentence : "Walla, hi-res metaballs."
It should have been : "Voilą, hi-res metaballs."
You can drop the sign on the "ą" but, it really is "Voilą" and not "Walla". Just so you know, because otherwise your post sounded intelligent. Thank you, come again.


April 07, 2002, 06:14 AM

If you want to optimize the speed then use spatial subdivision (perhaps you already do), like someone else suggested. Then for each subdivision, only consider the metaballs that are nearby. Pretty easy stuff, I think.
Or another idea I just thought up, do not calculate for each pixel on screen, but instead only calculate for each ball. Something like:

for (int i = 0; i < NROFBALLS; i++) {
for (int x = 0; x < ballWidth; x++) {
for (int y = 0; y < ballHeight; y++) {
pixel[x + xOffset][y + yOffset] += ball[x][y];

I once coded a 2D metaball java applet, you can see it at

I for one like the fact that each IOTD shouldn't be top notch (no offence meant) in order to appear here.


April 07, 2002, 06:19 AM

Yeah this place is starting to sound like the Dogs on Acid boards..

You go there for some advice on music production and everyone ends up giving your mum shit and bragging cos they have been into the 'scene' for 2 weeks longer than you have.. fuckin stupid


April 07, 2002, 07:17 AM

What the hell is going on here?!? Can we leave the childish shit plz?
I really don't want this place to turn into the gamedev forums :(

Wim Libaers

April 07, 2002, 07:58 AM

Why are you using that grid? Or is each of those dots a separate metaball?

Postalrat, why don't you post an IOTD from your "hello world" engine. If you're capable of making one.

And can the first post freakshow please relocate to their natural habitat? You may return if you evolve to become a more intelligent lifeform (a rock, for example).

By the way, space^qx, your image looks very nice, but perhaps a little more subdivision around the edges would improve it.


April 07, 2002, 08:11 AM

FUck you.


April 07, 2002, 08:18 AM

wim libaers
its a scalarfield he draws there. and so its a grid. a scalarfield is a 1d/2d/3d array of scalar-values, floats mostly (or unsigned chars or something) and the metaballs idea is to draw only the ones with a value above some threeshold (for floats mostly 0.5 with the full range from 0 to 1). that way you get objects from your scalarfield. they can be poligoniced afterwards if you want (find the edge of the mesh and draw this, like space^qx has done).


April 07, 2002, 11:44 AM

YOu better watch out or the insects will get you!


April 07, 2002, 12:03 PM

I actually know that - ever heard of a colloquialism?

Division By Zero

April 07, 2002, 12:07 PM

Kismet nx is kur tu ce aciradai :P
deja mano nikas vel kitas :))

Division By Zero

April 07, 2002, 12:12 PM

Dont worry be happy .. just enjoy yourself ;p

Division By Zero

April 07, 2002, 12:23 PM

My [meta]balls are better than yours;p


April 07, 2002, 12:45 PM

All 'dis talk about met-a-balls makes me -a- hungry.


April 07, 2002, 12:47 PM

Maybe if they get too bad he can move off-topic posts to a separate page and link to it.


April 07, 2002, 12:57 PM

Yes A. Colloquialism. He is the brother of E. Colloquialism. Anyway, Mr. A. Colloquialism and I get soapy all the time :D


April 07, 2002, 01:14 PM

Ok ok so i wrote your instead of you're. Not like this is english class.


April 07, 2002, 01:20 PM

That's awesome!!!! Tell me, is there anyway I could make it into a screensaver? I think it would really rock :)

That 3D one looks pretty cool too- anywahere I can download it?


April 07, 2002, 02:27 PM

Disabledan, I sent you the screensaver version.
Madcow, I actually already had that implemented.

I dunno why it's running "slow" on a 1.4ghz machine when it runs fine on my P550.

Ill give you guys something much cooler to drool at next time.


April 07, 2002, 04:19 PM

nor much of a forum with all the first posts going on :(


April 07, 2002, 04:50 PM

DSA ia a humorous, possibly intelligent (:)), and mostly non-aggressive person(see post one-up)...

Id say that we could do with a few more "IMHOs" rather than slagging matches...

everyone reads a post and misses the point sometimes... let those that miss it be.
If you do not like someone's critisism of your post, then it may be true that you shouldn't really be posting here.
Remember all: this is an open forum, and there are some unwritten rules.

think before posting, think twice before posting in critisism, think three times before posting in anger.

Ah the sweet mystery of life.

This thread contains 102 messages.
First Previous ( To view more messages, select a page: 0 1 2 3 ... out of 3) Next Last
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.