GLSL shader example

Metaballs with a Smooth SDF Union

The left half uses a hard union and the right half a smooth union. Blend width changes the neck geometry rather than blurring final color.

Live example

Edit the code and the preview updates as you type.

What to observe

Metaballs with a Smooth SDF Union.

Mechanism

The left half uses a hard union and the right half a smooth union. Blend width changes the neck geometry rather than blurring final color.

The controlling code

float a=length(p-vec2(-.3,.1*sin(u_time)))-.28,b=length(p-vec2(.3,-.1*sin(u_time)))-.28;float d=p.x<0.?min(a,b):smoothUnion(a,b,.05+.55*u_parameter);c=mix(c,vec3(.2,.8,.95),1.-smoothstep(-aa,aa,d));

Experiment

Set the smooth-union width .05+.55*u_parameter to .1, then .5. The neck between the right-hand droplets grows at the larger value, while the hard union on the left does not change.

Debugging and cost

Two circle distances are combined before one antialiased color mix, so this is a geometry-field blend. Replace smoothUnion(a,b,.05+.55*u_parameter) with min(a,b) to make both halves use the same hard boundary and remove the smooth bridge.

Built-in functions used

Learn it step by step