Metaballs shader preview: Gooey blobs that drift, merge and pinch apart.
ittybitty

Metaballs

Gooey blobs that drift, merge and pinch apart.

Code

The usage always matches the preview, layers and performance settings included. No build step or package.

Use as
Code view

Copy embed gives one block to paste into any page or site builder, no setup. For your own code: add metaballs.js, ittybitty-shader.js, runtime.js, pointer.js next to this page. Highlighted values follow the controls.

<!-- Quickest: one element. Size it with CSS; it fills its box. -->
<script type="module" src="./ittybitty-shader.js"></script>
<ittybitty-shader effect="metaballs" style="width: 100%; height: 480px;"></ittybitty-shader>

<!-- Or with JavaScript, for full control: -->
<canvas id="metaballs" aria-hidden="true" style="width: 100%; height: 480px; display: block"></canvas>

<script type="module">
  import { metaballs } from './metaballs.js';

  const canvas = document.getElementById('metaballs');
  const effect = metaballs(canvas, {
    showBackground: true,
    speed: 0.4,
    count: 6,
    size: 0.14,
    goo: 0.6,
    finish: 'glass',
    interactive: true,
    responsiveness: 0.5,
    colorA: '#ff8a5c',
    colorB: '#7b5cff',
    background: '#f1eee8',
    // Performance
    dpr: 1.5,
    adaptive: true,
  });

  // Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>

Details

Up to eight blobs share one field and melt together where they meet. Finish them flat, as soft glass or as chrome: the surface normal comes from the field's exact gradient, computed in the same loop, so shading costs almost nothing.

Payload
6.0 KB brotli for metaballs.js and ittybitty-shader.js and runtime.js and pointer.js, measured at build time. See the method.
Resolution
Device pixel ratio capped at 1.5.
Frame rate
Display rate.
When unseen
Stops rendering when the canvas leaves the viewport or the tab is hidden, and resumes where it left off.
Reduced motion
Shows a single still frame. Controls still update it.
Layers
Up to five effects fuse into one shader and one draw call. Filters such as dithering and halftone process the layers beneath them.
Browsers
Any browser with WebGL2: Chrome and Edge 56+, Firefox 51+, Safari 15+.
Licence
MIT. Copy it, change it, ship it.