@@ -22,6 +22,8 @@ kernel void
2222 float sum = 0;
2323 float3 colorSum = float3(0, 0, 0);
2424 float colorAccumulation = 0;
25+ float3 colorSumLink = float3(0, 0, 0);
26+ float greatestLinkWeight = 0.0;
2527
2628 char x, y;
2729
@@ -43,6 +45,7 @@ kernel void
4345
4446 float bendClose = 0.0;
4547 float bendCloseCount = 0.0;
48+ float red = 0.0;
4649
4750 for (x = 0; x < numberOfMetaballs; x += 1) {
4851 float distance1 = metaballDistances[x];
@@ -74,7 +77,18 @@ kernel void
7477 bendCloseCount += 1.0;
7578 }
7679
80+ red += step(0.4, weightedValue);
81+
82+ if (weightedLink > greatestLinkWeight) {
83+ greatestLinkWeight = weightedLink;
84+ colorSumLink = float3(0.0, 0.0, 0.0);
85+ colorSumLink += metaballColors[x] / distance1;
86+ colorSumLink += metaballColors[y] / distance2;
87+ colorSumLink /= (1 / distance1) + (1 / distance2);
88+ }
89+
7790 float metaballValue = step(0.5, weightedValue + weightedLink);
91+
7892 sum += metaballValue;
7993 }
8094 }
@@ -91,7 +105,12 @@ kernel void
91105 result += bendClose * 10;
92106 result = clamp(result, 0.0, 1.0);
93107
94− colorSum /= colorAccumulation;
108+ colorSum = colorSum / colorAccumulation;
109+
110+ if (result > 0.0 && red < 1.0) {
111+ colorSum = colorSumLink;
112+ }
113+
95114 colorSum *= result;
96115
97116 outTexture.write(float4(colorSum.bgr, 1), gid);