# Metaball color blending

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

## Recommended Posts

Hi all, I was wondering if anyone had any tips on how to implement blending of colors between metaballs. I've already written a basic implementation using a 2d marching cubes algorithm, but I'm wondering how to store a color for each metaball and blend between the colors when the metaballs connect. I'm looking to do something along the lines of this effect:

(image from wikipedia)
Track each metaball that contributes to a given vertex and then set the color to an average weighted by the distances from the vertex to the metaballs centers somehow?

Any help/tips/advice would be greatly welcomed!

##### Share on other sites
Presumably you're already calculating a distance-dependent weight function for each metaball when you run your marching cubes. Weighting colour contributions by the same or similar function could live in the same bit of code? Difficult to suggest the best approach without seeing your implementation.

##### Share on other sites

Presumably you're already calculating a distance-dependent weight function for each metaball when you run your marching cubes. Weighting colour contributions by the same or similar function could live in the same bit of code? Difficult to suggest the best approach without seeing your implementation.

I'm basically using a function that falls off to 0 at a specific distance (a multiple of a per-ball radius) and do a simple loop over my sampling grid ala:

for(X = 0 to MaxX) { for(Y = 0 to MaxY) { for(each metaball) { if metaball is within the max radius, feed it through the fall off function and add the resultant value to this grid point's value in the sampling grid array } } }

Then after the grid's been populated I run marching cubes (marching squares?) over each grid cell figure out what type of cell is it is, interpolate the edges as needed and draw the appropriate triangles for the cell.

##### Share on other sites
Disclaimer: I'm just imagining this off the top of my head so it might not work as I expect.
Instead of just recording an intensity at each grid point (the summed contributions from each metaball) you could also record the summed colour contributions weighted by the distance and normalized so the weights add to 1.

Say you had two metaballs A and B contributing to one point with distance-weights Wa and Wb and colours Ca and Cb.
Total weight W = Wa + Wb, which is what you use to segment your space in the marching cubes algorithm.
But also color C = (Ca * Wa + Cb * Wb) / W which is the weighted-average colour contribution from the balls.
(Generalise this to as many balls as required.)
Linearly interpolate the grid-point colours to determine the colour of each vertex you create.

Hope this helps, and apologies if it's way off!

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013593
×