How it works
Nothing here is a mesh or a sprite. Three to twelve droplets (seven by default) are spheres and teardrop-shaped round cones, written as signed distance functions and merged with a smooth minimum, so where two of them come close a liquid neck grows between them, and it tears when they part. Every pixel fires a ray into that field and sphere-traces to the surface. It is then lit by a procedural photo studio, as a mirror, an interference film or a lens of glass. The motion comes from a few springs on the CPU: a heavy body that only leans toward your cursor, light droplets that gather just short of the pointer, and the lightest two or three, which run along the path your cursor just took, so a fast stroke pulls a string of beads out of the pool that necks off and falls back in.
Pipeline (per frame)
CPU pointer → presence (eases in within ~0.2 s, out from 2.2 s after the last move)
12 blobs: spring toward mix(home, target, pull × attraction), ω = speed/√r, ζ = damping
target: an arc 1.35r + k past the tip, on the pool's side, behind the motion
the 2–3 lightest: the pointer's path 80 / 160 / 240 ms back (ring of 64 samples)
+ that point's velocity × the spring lag 2ζ/ω, full pull, ω × 2.2
+ clear zone round the tip (target and force) + soft contact (repel < 0.9·(rᵢ+rⱼ),
cohesion just outside; softer for the beads) · click = radial splash
· speed capped at 16 units/s by magnitude · 240 Hz substeps
tail point on its own critically damped spring (ω 13) → round cone, length eased
into 1.15r, tail radius → 0.3 head, head radius solved for equal volume
upload: head (xyz, r), tail (xyz, r), bound sphere ×12 · shadow capsules ×12 (light theme)
│
├─▶ MARCH low RGBA16F 1408×792 (scale 0.55 of 2560×1440) premultiplied, tone-mapped
│ per ray: cull 12 bound spheres → mask (r + max(6k, .55·size)) + interval (r + 3.2k)
│ sphere trace ≤ 72 steps over cubic smin of the masked blobs; miss → closest
│ approach → coverage (silhouette AA); a near miss passed before the hit → inner
│ silhouette: shaded at both points, blended by its coverage
│ · tetrahedral normal (4 map) · |fwidth(R)| → env prefilter width
│ studio ground + floor glow · sky · horizon line · 5 softboxes, each integrated over
│ the prefilter width (box ⊗ box per axis, so sub-pixel strips dim, not dot)
│ chrome/gold AO (4 map) · reflect → cull + cone trace ≤ 30 steps without the primitive
│ we're on; near a seam traced twice, once without each of the two nearest,
│ blended 50/50 on the seam · fades out where R turns > 0.2–0.6 rad/pixel
│ → studio(R) or the neighbour's mirrored studio, prefiltered by its spread · F0
│ film same bounce × film LUT(2·n·d·cosθt) over a pearly, part-transparent body
│ glass refract in → trace −map inside ≤ 40 steps → exit normal → per wavelength (6,
│ IOR ± dispersion) Schlick at the exit: (1−F)·refracted + F·inner reflection
│ · key light ×0.4 through the lens · Beer–Lambert · backlit strips to refract
│ · where |fwidth(exit)| > 0.15–0.4: a blurred lookup along it · Fresnel mix
├─▶ BRIGHT b1 RGBA16F 704×396 4-tap box, soft knee on the brightest channel (dark)
├─▶ DOWN ×2 b2, b3 RGBA16F 352×198, 176×99 dual filter (dark)
├─▶ UP ×2 u2, u1 RGBA16F 352×198, 704×396 (dark)
├─▶ SHADOW RGBA8 640×360 smooth union of 12 projected capsules (light)
└─▶ COMPOSITE canvas 2560×1440 backdrop (+ glass backlight) · cast shadow
· Catmull-Rom 5 taps (1 tap where the 2×2 is empty)
· bloom as a screen blend · sRGB · dither
once at load: shaders built in parallel (KHR_parallel_shader_compile, polled; the stage shows
its CSS background meanwhile) · thin-film LUT 512×1 RGBA8 (CIE-integrated)
· dispersion weights (6 wavelengths, 3 on phones)
every 30 frames: GPU time, or frame intervals where there is no GPU timer → adaptive march scale
phones: ≤ 40 steps, no bounce, 3 dispersion taps, march scale × 0.85
7 draws per frame on dark presets, 3 on light ones
The ideas that matter
- Culling from the smooth minimum’s support. iq’s cubic smooth minimum with blend width
kchanges nothing once two distances differ by more than6k, and each merge swells the union by at mostk. So every ray tests the twelve bounding spheres twice. Spheres grown bymax(6k, 0.55 × size)give the mask of blobs thatmap()must include. Along the ray, excluding the others is exact, not an approximation; the 0.55 × size floor keeps neighbours in reach of the normal and AO taps that sit a little off the ray. Spheres grown by3.2kgive the interval where a surface can exist, so the march starts at the first entry and stops at the last exit. Pixels whose rays meet no sphere cost one loop and nothing else. A debug run with culling switched off rendered the same image. - Teardrops that taper and curve with the path. A moving blob stretches into a round cone: a sphere at its head, a smaller one at its tail, a tangent cone between. The tail end is its own point, on a critically damped spring that chases the head, so it trails toward where the droplet was a moment ago. Droplets turning on different paths therefore point their tails in different directions instead of all lying parallel to the motion. The tail length is eased into a soft cap of 1.15 times the radius (a tanh, so a fast droplet never locks into one fixed shape), and the tail radius tapers to 0.3 of the head as it lengthens. The head radius is solved each frame so the volume stays that of the resting sphere. An earlier version stretched along the velocity, tapered only to 0.6 and capped hard at 1.7 r. Ordinary brisk mouse moves hit that cap, so droplets read as parallel pills rather than drops.
- Exact round cones, because chrome shows every kink. The first version used the common cheap capsule whose radius is lerped along the segment. That field is continuous but its gradient jumps at the two end caps, and in a mirror that showed as hard straight cuts across every moving blob. The exact round cone (after iq) is C1 across the joins. The smooth minimum is the cubic one (C2) for the same reason: the necks are where reflections are most curved, and a C1 fillet shows a crease.
- Anti-aliasing by prefiltering the studio. The environment is analytic: a ground/sky split at a crisp horizon (the liquid-metal signature line along every blob’s equator), a sky gradient, and five softboxes. Every light is integrated over a blur angle rather than point-sampled: per axis, a box of half-width
aseen through a filter of half-widthwcontributesclamp((min(u+w, a) − max(u−w, −a)) / 2w, 0, 1). That keeps the energy, so a strip light that is narrower than a pixel’s footprint (at a pinch neck, say) goes dim and wide instead of breaking into one bright dot per texel. The blur combines (in quadrature) the roughness angle with the full|fwidth(R)|, how far the reflected ray turns from one pixel to the next. An earlier version widened only the edges, by half that, and left sub-pixel strips at full brightness: the necks were stippled. Roughness maps to the blur angle linearly at the low end (0.12 rad per unit, rising to 0.8 rad at 1), so the first tenth of the slider already softens the boxes. Silhouettes get coverage from how close a missing ray came to the surface, in pixels, and that edge pixel is shaded at the point of closest approach. Inner silhouettes (a blob seen against another one behind it) get the same treatment: the march remembers a near miss it passed before its hit, and that pixel is shaded at both points and blended. What is left is geometry finer than a march texel, such as a deep, narrow crevice between two lobes: it can still step slightly, more so at the phone’s coarser scale. There is no temporal accumulation, so nothing ghosts. - One inter-reflection bounce, cheaply, and continuous across seams. Mirror blobs that only reflect the studio look pasted on. Here each reflected ray is culled and traced again (≤ 30 steps), so necks and neighbours reflect each other. A sphere or a round cone is convex and can’t see itself, so the primitive the ray leaves from is dropped from that trace. Every raw primitive is ≥ 0 on the union surface, so the ray still starts outside everything. That removed the crawl out of its own bounding sphere and cut the bounce from about 1.5ms to about 0.4ms per frame. But “the primitive we’re on” flips at the seam where two primitives are equally near, and with it the set of neighbours the ray may hit. The previous version faded the bounce out near that seam, and on a smooth mirror the horizon then ran flat, up a straight ramp along the (nearly planar) seam, and flat again. Now, near a seam, the ray is traced twice, once without each of the two nearest primitives, and the two are blended by the distance from the seam: 50/50 on it, from both sides, so the reflection is continuous. The bounce is a cone trace whose width follows the reflected beam (a pixel plus
|fwidth(R)|per unit of distance), so a mirrored silhouette is at least a pixel wide. The second reflection is prefiltered by its own spread: the first one’s, plus the neighbour’s curvature across the beam, divided by the cosine at the neighbour, because a beam meeting it edge-on is stretched along it. Without that, each neighbour’s rim mirrored a thin bright line of single-pixel dots. The bounce still fades out where the reflected ray turns faster than 0.2–0.6 rad per pixel, which is only the tightest pinches. - Thin film from the spectrum, not a rainbow ramp. A soap film of thickness
dreflects in proportion to1 − cos(2π·OPD/λ)withOPD = 2·n·d·cosθt(n = 1.33, one π phase flip). At load, that is integrated over 101 wavelengths against the CIE 1931 colour-matching functions (Wyman, Sloan & Shirley’s analytic fit), converted to linear sRGB and normalised so a non-interfering film is white: a 512-entry LUT. The shader varies the thickness with slow swirls and thins it toward the top (drainage), mixes 28% white back in for a pastel read, and lays it over a pearly body that is 40% see-through. - Glass refracts twice, with Fresnel on the way out, and has something to bend. The ray refracts in, traces the inside using
−mapas the distance to the exit, and refracts out at six wavelengths whose IORs span ± dispersion, each weighted by its CIE colour. Each wavelength gets its own Schlick Fresnel at the exit, using the cosine on the air side, which reaches 1 exactly at that wavelength’s critical angle. So the transmitted share fades smoothly to nothing as total internal reflection approaches. The reflected share heads back into the body; a blurred lookup along it at 0.6 strength stands in for light that leaves after more bounces (at 0.3 the thick parts read as black obsidian). With a hard switch instead, six slightly different critical angles drew a dark disc ringed in saturated cyan. Clear glass in front of a black page has nothing to refract, so the glass studio is backlit. Two soft, out-of-focus strip lights stand on the page either side of the pool, and two brighter ones sit just out of view. The glass inverts and bends them into bars with rainbow edges across its face, not only at its rim. Where the exit direction turns faster than one trace per pixel can follow (a pinch neck, where it drew a flat, hard-edged “X”), the transmission falls back to a blurred lookup along the mean exit ray. That test is a derivative, so the glass parts are computed first and mixed in uniform control flow. The key light is dimmed to 0.4 for what is seen through the lens, so the refracted highlight keeps a gradient instead of clipping. Beer–Lambert tints the glass by path length. - A tone curve that leaves the page alone and keeps highlights shaped. The tone map is the identity below a knee (0.72 on dark studios, 0.86 on light ones, just above the light page colour), then a soft rational shoulder
e / (1 + e)on the brightest channel (hue preserved, so gold highlights stay gold), drifting to white only for very hot values. The backdrop is the CSS background colour plus a faint centre lift (on dark) or a slight warm-to-cool tint (on light). Because the tone curve leaves those values untouched, the page colour seen through the glass and the soap film, and the area round the blobs, blend into the page’s edges with no visible frame. The dark key softbox (2.9, falling off as1 / (1 + 2.2 r²)) shows a hot centre fading toward its crisp edges. Bloom is added as a screen blend, so it glows into the dark around a highlight but can’t push a broad one, like the overhead box, to flat white: no pixel of the default frame clips. A faint floor, lit toward the camera (0.032 linear), gives the dark lower half of every blob a gradient, so it reads as a curved surface rather than a black silhouette under the horizon line. - Motion that reads as liquid, and leaves the pointer clear. Each blob has a pull (0.12 for the heavy body, up to 1 for the smallest droplets) that sets how far its spring target moves from its home in a slowly drifting golden-angle cluster toward the cursor. Cursor attraction scales it: 0.7, the default, gives the tabled pulls, and 1 lets the heavier blobs reach the cursor too. The pulled targets sit on an arc 1.35 r + k from the tip, on the side that faces the pool and leans behind the cursor’s recent motion, so the droplets arrive as a wake and wait just short of the pointer. An arc, not a ring: three droplets spaced round the cursor fuse, through the smooth minimum, into a torus with a dark hole at the tip. The two or three lightest droplets follow the cursor’s own path instead, at the points it passed 80, 160 and 240 ms ago, once those points are clear of the arc. Their springs run 2.2× faster, and each target is pushed ahead by that point’s velocity times the spring’s lag (2ζ/ω), so a bead sits on its point instead of trailing a further spring lag behind. A fast stroke therefore pulls a string of beads out of the pool that necks off and re-merges when the cursor stops; when it slows, the history collapses onto the tip and the beads rejoin the arc. Before this, everything chased one point near the cursor and a quick stroke only made the pool lean. A clear zone (target projection plus a soft push, on screen at each blob’s depth) keeps even the heavy body from coming to rest over the tip. Soft contact keeps the blobs from collapsing into one ball: repulsion inside 0.9× the radius sum, light cohesion just outside it, a third as strong for the beads while the cursor is about, so they slip through the pool after it. Speed is capped at 16 units/s by magnitude, so the direction of a fling is kept. Spring frequency scales as 1/√r, so small droplets react first. 2.2s after the last move the pull eases off and everything flows home, to a spiral wide enough that a droplet or two rests apart from the body. The default damping ratio is 0.75, viscous with only a slight settle; lower it for jelly. A click throws the nearby metal apart. Blobs that appear or vanish (the count slider) sink below zero radius by 6.5k, past the smin’s reach, so they melt in and out instead of popping.
- It comes to rest before it stops. The shell stops rendering 8s after the last activity. Over the last few seconds the drift eases out and, finally, simulation time itself slows to zero, so the loop ends on a resting frame rather than freezing mid-wobble.
Parameters
Presets
Performance & compatibility
- Measured by the harness (Chrome, ANGLE-Metal, Apple-silicon Mac, 1280×720 at DPR 2, so a 2560×1440 backing store, ray-marched at 1408×792) during its 1.5s pointer sweep with the default Chrome preset. The last two full runs read GPU 5.4 / 7.8ms and 6.3 / 9.6ms (mean / p95 per frame), JS 0.1–0.2ms, a steady 60 fps (p95 frame time 16.7–16.8ms, no frames over 25ms). The per-frame GPU timer also counts whatever else is on the GPU, and other agents’ pages and harnesses were running all through this session. So treat the figures as a range: this session’s desktop runs read 2.7–6.3ms mean and 5.6–9.6ms p95, the quietest interleaved round 2.5 / 5.6ms, and one early run 7.9 / 10.9ms. All are inside the 12ms limit; the contended ones are over the 8ms p95 the library prefers.
- Per preset. One browser, the presets interleaved in five rounds of the harness’s 1.5s sweep, render scale pinned, median of the rounds’ mean and p95, with the quietest round in brackets. The spread between rounds (2–3× on the mean) is contention, not the presets, so the rows are close to each other within noise:
Preset GPU mean GPU p95 What it adds Chrome 4.7ms (3.4) 7.8ms (7.8) the baseline: march, AO, one bounce (twice near seams), bloom Iridescent 5.0ms (2.8) 8.5ms (5.0) film LUT; no bloom, adds the cast-shadow pass Glass 5.4ms (2.9) 9.1ms (6.5) interior trace (≤ 40 steps), 6-wavelength exit, blurred fallback, backlight Gold 4.3ms (3.7) 9.2ms (6.7) eight blobs and wider necks (k 0.36): more blobs per ray - What drives the cost. In the same interleaved rounds, render scale pinned at 0.35 read 3.9 / 5.5ms against 4.7 / 7.8ms at 0.55. Fitting cost = fixed + march × scale² to that leaves roughly 2–3ms that doesn’t depend on the march resolution: the full-resolution composite and the bloom chain. The rest is the ray march, and it scales with the pixels the blobs and their bounds cover, so it grows with Blob size, Smooth-min k (it widens every ray’s cull mask, the support of the smooth minimum being 6k) and Blob count. Those ranges are capped at 0.32 and 0.6. At the caps with twelve blobs and the scale pinned at 0.55, it ran 8–14ms mean, 10–20ms p95 over three contended rounds (9.4 / 12.6ms median). Max steps only matters at grazing silhouettes. The anti-aliasing added this round (two bounce traces near seams, a second shading at inner silhouettes, the box-integrated lights) costs something, but interleaved A/B runs against the previous version disagreed with each other (from 30% more to 20% less), so it is within this session’s noise. Memory is about 15MB of render targets at 2560×1440 (8.9MB of it the ray-march target).
- Adaptive render scale. Every 30 frames the page checks its own timing. Where
EXT_disjoint_timer_query_webgl2is available (Chrome on desktop) it reads GPU time: if more than 10% of frames took over 11ms, the march resolution drops in proportion (by √(7.5ms / mean) per side), and it steps back up by 10% once frames are under 6ms again. Safari, iOS and most Firefox builds have no GPU timer, so there it reads frame intervals instead: more than 3 of 30 frames over 20ms scales down by √(16ms / mean interval). Frame time can’t show headroom, so it probes back up by 10% after a calm second, and each probe it has to undo doubles the wait (up to 16s). Either way the scale goes down to half the slider value at most, and never below 0.35. Tested with?notimerat every control’s maximum, the frame-time path went from scale 1 to 0.76 within 1.3s, probed up, and settled at 0.56 at 60 fps. The upsample is a Catmull-Rom filter and the shading is analytic, so a lower scale softens slightly rather than breaking up. At the caps the GPU path settles at its floor, an effective scale of 0.35 (about 6.7 / 10ms). With every control at its maximum (render scale 1, 128 steps, twelve big blobs) it reaches its floor of 0.5: about 12–13ms in the quietest round, so 60 fps, but 19–22ms when other pages shared the GPU, where it drops to about 50 fps.?fixedscaleturns adaptation off for measuring. - Shader compile. The six programs are compiled with
KHR_parallel_shader_compile: the page pollsCOMPLETION_STATUS_KHRand starts the first frame once they’re linked, keeping the canvas hidden (so the stage shows its CSS background) instead of blocking the main thread. A cold build takes about 120ms (measured in a fresh browser), less once the browser has cached it. The shading for inner-silhouette pixels runs in a two-pass loop, so the bounce and glass code is emitted once, not twice. Without the extension it links synchronously. - Requirements. WebGL2. Half-float render targets are used when
EXT_color_buffer_floatis present, and RGBA8 otherwise, so the page still runs without float support. Without WebGL2 the page shows a message card over the captured poster frame. - Mobile. Drag to pull the metal, tap to splash. On coarse pointers the ray-march scale is reduced by a further 15% (390×844 at DPR 3 renders a 780×1688 canvas, marched at 365×789), primary steps are capped at 40, the inter-reflection bounce is off and glass uses three dispersion wavelengths. A 12-step bounce was tried first; it ran out of steps along necks and drew stripes and crumpled fragments at the phone’s coarse scale. The frame-time adaptation above covers phones, which have no GPU timer. The scene is laid out in units of the short side, so a portrait phone gets the same blobs at the same size relative to its width. In the harness’s 390px touch run (emulated on the Mac’s GPU, so real phones will be slower and lean on the adaptation), dragging ran at 49–51 fps, and there is no horizontal overflow. The controls become a bottom sheet over the lower 62% of the screen. While it is open, the camera eases down so the pool rises into the strip of stage left above the sheet, and the touch mapping moves with it, so tuning isn’t blind. On touch screens the clear zone holds only while a finger is down.
- Idle and visibility. The loop stops 8s after the last activity (measured: 8.10s after the last move, no frames after). Because the drift and then time ease out first, it stops on a resting frame. The loop also pauses off-screen and in hidden tabs. The gallery embed renders at DPR 1 with a 0.75 ray-march scale, slightly bigger blobs (0.29), narrower necks (k 0.2) and a stronger pull (0.65). Its ghost pointer circles the centre of the card, so the pool sits in the middle and a droplet necks off toward it; the poster is captured that way. The home cluster is centred on its mass-weighted centroid, because the golden-angle spiral alone sat 0.15 above centre.
- Reduced motion. 3.3s of the intro is simulated on the CPU only: the ghost stroke, then the cursor held to the right so droplets reach out of the body. That is drawn once as a still, with a “Play anyway” button, and the hint reads “Still frame · press Play to interact” until it is pressed. A resize redraws it. A change to a physics parameter (blob count, size, k, stretch, attraction, springs, or a preset that sets them) simulates it again from the start, so new blobs appear in it.
References & credits
- Inigo Quilez, “Smooth minimum”: the normalised polynomial family, their support and their bounds. iquilezles.org/articles/smin; article, licence not stated (ideas used, no code copied).
- Inigo Quilez, “Distance functions” (round cone) and “Round Cone - distance 3D”. iquilezles.org/articles/distfunctions (article, licence not stated), shadertoy.com/view/tdXGWr (MIT).
sdBlobis adapted from the MIT Shadertoy code. - Inigo Quilez, “Normals for an SDF”: the tetrahedral 4-tap normal and keeping it in a loop to avoid inlining
map()four times. iquilezles.org/articles/normalsSDF; article, licence not stated. The AO estimate follows his “Raymarching - Primitives”, shadertoy.com/view/Xds3zN, MIT. - John C. Hart, “Sphere Tracing: a geometric method for the antialiased ray tracing of implicit surfaces”, The Visual Computer 12(10), 527–545, 1996. doi.org/10.1007/s003710050084; paper, © Springer (method only).
- Benjamin Keinert, Henry Schäfer, Johann Korndörfer, Urs Ganse, Marc Stamminger, “Enhanced Sphere Tracing”, STAG 2014. doi.org/10.2312/stag.20141233; paper, © the authors / Eurographics (method only). Its over-relaxed stepping was tried and measured slower for this scene.
- Chris Wyman, Peter-Pike Sloan, Peter Shirley, “Simple Analytic Approximations to the CIE XYZ Color Matching Functions”, JCGT 2(2), 2013. jcgt.org/published/0002/02/01; paper, distributed under the journal’s Creative Commons BY-ND licence. Its published fit coefficients drive the thin-film LUT and the dispersion weights.
- Marius Bjørge, “Bandwidth-Efficient Rendering”, SIGGRAPH 2015 course Moving Mobile Graphics: the dual-filter blur used for the bloom. Course listing: history.siggraph.org/person/marius-bjorge; talk, licence not stated (method only; I found no stable URL for the slides).
- Catmull-Rom from bilinear taps: Matt Pettineo (TheRealMJP), gist.github.com/TheRealMJP/c83b8c0f…, MIT. The 5-tap form is from Jorge Jimenez, “Filmic SMAA: Sharp Morphological and Temporal Antialiasing”, SIGGRAPH 2016 Advances in Real-Time Rendering, advances.realtimerendering.com/s2016 (talk, licence not stated). Dither: Jimenez’s interleaved gradient noise, “Next Generation Post Processing in Call of Duty: Advanced Warfare”, SIGGRAPH 2014, iryoku.com/next-generation-post-processing… (talk, licence not stated; a one-line formula).
- Research:
research/rd-metaballs-sdf.md(thesdf-mercury-followercandidate, smooth-min variants and bounds, materials, the pointer-history chain of the Codrops droplets, of which only the idea is used) andresearch/distortion-glass-post.md(refraction, dispersion, cast shadows) in this library. Engine lineage and taste notes: the stable-fluids cursor trail in the Russ Hype Machine page, the library’s reference implementation. All code on this page is written from scratch apart from the adaptedsdBlob.