ISF - Shadertoy - Metaball garbage MtyGR3
#define ISSOLID 1
#define ISTHRESHOLD 0
#define posnum 7
#define negnum 2
float metaball(in vec3 ball, in vec2 testPoint){
return ball.z/length(ball.xy - testPoint);
}
void main()
{
vec2 uv = gl_FragCoord.xy / RENDERSIZE.xx;
vec3 points[posnum];
vec3 colours[posnum];
points[0] = vec3(abs(0.1 + sin(TIME)), 0.2 + 0.2 * cos(TIME), .15);
colours[0] = vec3(1., 0., 0.);
points[1] = vec3(0.5, abs(0.3 + .2 * sin(TIME * 0.7 + 5.)), .1);
colours[1] = vec3(0., 1., 0.);
points[2] = vec3(abs(0.4 + sin(TIME)), 0.4 - 0.2 * cos(TIME), .3);
colours[2] = vec3(0., 0., 1.);
points[3] = vec3(0.43,0.25 + .1* cos(TIME), .15);
colours[3] = vec3(1., 1., 0.);
points[4] = vec3(0.42 + .4* sin(TIME),0.32 - .1 * sin(TIME * .2), .2);
colours[4] = vec3(1., 0., 1.);
points[5] = vec3(abs(0.12 + .3 * sin(TIME - 10.)),0.52 + .25* cos(TIME), .07);
colours[5] = vec3(0., 1., 1.);
points[6] = vec3(0.2+ .25* cos(TIME),0.6 - .1 * cos(TIME + 5.), .2);
colours[6] = vec3(1., 1., 1.);
vec3 negPoints[negnum];
vec3 negColours[negnum];
negPoints[0] = vec3(0.64, 0.25, .2);
negColours[0] = vec3(1.2);
negPoints[1] = vec3(0.34 + .3 * sin(TIME * 2.), 0.25 + .2 * sin(TIME* 0.1), .15);
negColours[1] = vec3(1.);
vec3 rgb;
for (int i = 0; i < posnum; i++){
rgb += colours[i] * metaball(points[i], uv);
}
for (int i = 0; i < negnum; i++){
rgb -= negColours[i] * metaball(negPoints[i], uv);
}
#if ISTHRESHOLD == 1
float threshold = 0.65;
if (rgb.x/2. <= threshold){
rgb.x = 0.;
}
if (rgb.y/2. <= threshold){
rgb.y = 0.;
}
if (rgb.z/2. <= threshold){
rgb.z = 0.;
}
#if ISSOLID == 0
float border = 0.03;
if (rgb.x/2. >= threshold + border ||
rgb.y/2. >= threshold + border ||
rgb.z/2. >= threshold + border){
rgb = vec3(0.0);
}
#endif
#endif
gl_FragColor = vec4(rgb/2., 0.0);
}