• Advertisement
Sign in to follow this  

Fake metaballs with different colors and separation

This topic is 2337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi

I´m making a game that requires fast metaball rendering, so i´m faking it by rendering faded sprites, 1.0 alpha in the center to 0.0 alpha. Then i have a simple shader that colors the blobs depending on the strength of the combined alpha value, i pass the alpha value to a ramp texture that selects the right color value to use. This works really well and i get nice looking metaballs.

My problem is that i need to have 5 different colored metaballs that dont mix with eachother, attached is a picture of what i´m trying to achieve. Im using box2D with circle shapes, so the metabal sprites can never fully go trough eachother. I also found a flash game that does exactly what i want http://www.flashgames247.com/game/flash-fun-games/gluey.html.

Any tips and trick would be really helpfull.

Thanks
Kristofer

Share this post


Link to post
Share on other sites
Advertisement
I thought of that to, but then the blobs would overwrite eachother. Look at the flash game i mention, there you get a more squizy effect between the blobs, its like they push eachother away, and not owerwriting colors.

Share this post


Link to post
Share on other sites
If you add the alphas of same-color blobs together, then subtract the alphas of different-color blobs, then I'd think that you would get the desired squeezing result. I suspect this would require a pre-pass to calculate all the groups alphas before anything is rendered, otherwise you would end up with the color rendered first "dominating" the scene, and the remaining colors being successively squeezed, until the last-drawn color would be squeezed way out of proportion. Seems like, given 4 colors as in the linked game, you could do a pass and calculate all the alphas, storing the alphas into the channels of an RGBA texture. Then you could do a color pass, where you draw the texture. For each pass, you would obtain the RGBA value, from it obtain the alpha value for the currently-being-drawn color, and subtract the alphas for the other colors. The value you have left could be tested against the ramp, and if it passes the threshold, the output fragment would be colored the currently-being-drawn color.

For instance, here is an image of 4 blobs being drawn as alphas into the red, green, and blue channels of a texture:

QFBQo.jpg


Now, the render pass on such a generated texture would look for the greatest value out of Red, Green and Blue and Alpha of the color component (although in my example, I'm not using Alpha since JPG doesn't want an alpha channel). The greatest component then would have the values of the lesser components subtracted from it, then the result would be tested. In this case, if the result is >0, then a pixel of the blob color is drawn. The result of it looks something like this:

mOFOw.jpg


Different thresholds create different membranes. Here is a threshold of 0.25:

Jxqwc.jpg


The actual alpha value could also be manipulated to perform certain other effects like fading/blending the edges of the blobs, perturbing the surface normal to make the blobs look bumpy, etc...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement