Metaballs

First appeared 1982 · Jim Blinn — Jim Blinn, "blobby" implicit surfaces (1982). · timeline ↗

community / folk Name — Blinn's own 1982 term was the "blobby model"; "metaballs" is a later community name for the same implicit-surface technique, not a personal eponym.

In one line Smooth, blob-like forms built by summing the implicit fields of several sources, so nearby blobs merge organically. The surface is the contour where the summed field equals a threshold, usually extracted with marching squares.

Metaballs · Open in new tab ↗ · Motion begins only when you press Run.

The code

The actual sketch behind the demo above — sandboxed and reproducible. This is the whole thing.

metaballs/index.html
const SEED = Math.floor(Math.random()*1e9);

// Animated metaballs: sum of inverse-square fields from moving charges,
// thresholded into glowing blobs. Rendered at low res for speed.
const R = 200;
let balls = [];

function setup() {
  randomSeed(SEED);
  const s = Math.min(windowWidth, windowHeight);
  pixelDensity(1);
  const cnv = createCanvas(R, R);
  cnv.elt.style.width = s + 'px';
  cnv.elt.style.height = s + 'px';
  cnv.elt.style.imageRendering = 'auto';
  const n = 5 + Math.floor(random(4));
  for (let i = 0; i < n; i++) {
    balls.push({ x: random(R), y: random(R), vx: random(-1,1), vy: random(-1,1), r: random(18, 34) });
  }
}

function draw() {
  for (const b of balls) {
    b.x += b.vx; b.y += b.vy;
    if (b.x < 0 || b.x > R) b.vx *= -1;
    if (b.y < 0 || b.y > R) b.vy *= -1;
  }
  loadPixels();
  for (let y = 0; y < R; y++) {
    for (let x = 0; x < R; x++) {
      let sum = 0;
      for (const b of balls) {
        const dx = x - b.x, dy = y - b.y;
        sum += (b.r * b.r) / (dx*dx + dy*dy + 1);
      }
      const idx = 4 * (y * R + x);
      // colour ramp by field strength
      const v = Math.min(1, sum);
      let r, g, bl;
      if (v < 1) { r = v*20; g = v*30; bl = v*60; }
      else {
        const t = Math.min(1, (sum - 1) * 0.5);
        r = 40 + t*215; g = 60 + t*120; bl = 120 + t*100;
      }
      pixels[idx]=r; pixels[idx+1]=g; pixels[idx+2]=bl; pixels[idx+3]=255;
    }
  }
  updatePixels();
}

Open the demo source ↗

How it works

Give each "ball" a falloff function whose value is high near its centre and fades with distance — e.g. f(p) = r² / |p − centre|² (Blinn used a Gaussian). Then: 1. At every sample point, sum the contributions of all balls into one scalar field. 2. Choose a threshold (iso-value); points where the sum exceeds it are "inside". 3. Extract the iso-contour of that threshold (marching squares in 2D, marching cubes in 3D) to get the merged outline/surface. Because fields add, two balls that approach each other bulge and fuse into a single smooth shape; moving the centres animates the melding.

Parameters

Lineage

Related
Marching Squares / Contours, Raymarching with SDFs

Frequently combined with

Works using this algorithm (1)

Metaballs
stanko-tadic

Last updated 2026-07-16