• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Image-Space 3D Metaballs

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

9 replies to this topic

### #1Akitsune  Members

Posted 09 March 2010 - 10:43 AM

### #2MJP  Moderators

Posted 09 March 2010 - 11:54 AM

It's not too hard to add normals. Basically when you're rendering your billboards, you need to calculate xy values such that x and y are of the range[-1, 1] (where (-1, -1) is the bottom left corner of your quad, and so on). Then you output these x and y values along with your weight value (height), and you scale x and y by the weight.
float dist = length(xyPos);float weight = CalcGaussianWeight(dist);xyPos *= weight;return float4(xyPos, 0, weight);

Then in your final pass where you sample the summed weights, you can calculate a normal like this:
float3 normal = normalize(float3(sample.x/sample.w,                                 sample.y/sample.w,                                  max(sample.w - 0.08f, 0)));

Of course you may need to negate your Z depending on your coordinate system.

This is a screen from a little demo I made with this technique a while back:

### #3Akitsune  Members

Posted 09 March 2010 - 08:59 PM

Awesome - helpful as always, MJP.

I decided to use cubemap reflections, a non-spherical (paint splat) heightmap/brush, with normals:

[Edited by - Akitsune on March 10, 2010 3:59:09 AM]

### #4mokaschitta  Members

Posted 09 March 2010 - 11:22 PM

this is awesome! I currently used raycasting combined with spatial hashing on the GPU to make realtime 3D metaballs but this is so much simpler :)

I will give this a try for sure!

edit:
anyways I am curious what happens if you move the camera? does that look weird?

### #5Akitsune  Members

Posted 09 March 2010 - 11:41 PM

Quote: Original post by mokaschitta
this is awesome! I currently used raycasting combined with spatial hashing on the GPU to make realtime 3D metaballs but this is so much simpler :)

I will give this a try for sure!

edit:
anyways I am curious what happens if you move the camera? does that look weird?

Thanks! No, not like you'd expect from a billboard method - that's what makes it pretty neat.

Updated the demo, WASD to see for yourself:

http://astraios.net/test/Meta.zip

I'd share the source, but I'm using 3D middleware and it's horribly organized. If someone REALLY wants it, just ask.

PS: Try changing the Drop.png texture to any other grayscale picture.

edit: fixed to new link, source included

Edited by Akitsune, 05 March 2012 - 01:50 PM.

### #6mokaschitta  Members

Posted 10 March 2010 - 05:00 AM

Hey,

I am on a mac, so I cant test your demo. Anyways I thought about the method a little more and correct me if I am wrong:

this method interprets all metaballs having the same z value right? I could move one metaball in front of all the others.

An also no matter how far away a metaball is, it will contribute to the current pixel due to the additive blending.

Did you solve that anyhow or is that a limitation you have to take when using this method?

### #7Akitsune  Members

Posted 10 March 2010 - 10:29 AM

Right. I render the billboards using back-front sorting, so the z position is proper.

Correct - metaballs contribute from any distance. This is a limitation, but it isn't a huge one and is barely noticeable - this is what the threshold and billboard size should be adjusted to minimize artifacts. I'm working on adding depth so I can retrieve the world position from the metaballs and eventually use triplanar texturing which like likely have artifacts due to this.

### #8mokaschitta  Members

Posted 10 March 2010 - 11:11 AM

cool, let us know how it works out. if you get correct depth to work somehow this is a neat method.
I want to be able to move metaballs in front of each other without resulting in one big blob (as it would be with this method).

### #9MarkS  Members

Posted 11 March 2010 - 11:42 AM

I tried your demo on Windows 7 x64 and it gives me an error saying that is is not a valid Win32 application.

### #10Akitsune  Members

Posted 11 March 2010 - 12:47 PM

Quote:
 Original post by maspeirI tried your demo on Windows 7 x64 and it gives me an error saying that is is not a valid Win32 application.

Looks like I forgot to build in x86 mode, sorry! Uploading a fixed version.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.