How it works
One sheet of silk, twisted along its length and rolled edge-on in travelling folds. It is a single 49,000-triangle mesh whose shape is computed entirely in the vertex shader. Its colour comes from an authored palette ramp. Its texture is a few hundred iso-lines of the across-coordinate, each held to a constant pixel width by its own screen-space derivative. Its light comes from the facing ratio: where the sheet turns edge-on, the filaments crowd together and the fold glows. The cursor is a soft obstacle. The ribbon leans away from it, and crossing it rolls the sheet into a glowing fold that travels down its length and eases out over about three seconds.
Pipeline (per frame)
CPU (~0.1 ms of JS)
pointer ──▶ critically damped spring (ω = 9 rad/s, about 0.2 s of lag)
centre curve, mirrored from the vertex shader ──▶ 128 cells projected to the screen
forces push away from the cursor (−tanh of the signed distance across, Gaussian falloffs)
+ drag and twist in proportion to the cursor's speed across the ribbon
(the twist footprint is 1.8× wider along the ribbon than the push)
wake two damped wave equations along the ribbon, bend and twist:
q'' = c²·q_xx − ω²·q − 2γ·q' + F c = 1.15 units/s
bend ω = 2.1 rad/s, γ = 1.25 /s · twist ω = 1.1 rad/s, γ = 0.7 /s
integrated in substeps of ≤ 1/240 s together with the spring
──▶ texSubImage2D uWake RG16F 128 × 1
ambient φ advances at speed × (1 − 0.3·hush); a crossing sets hush → 1, which decays in ~1.5 s
k·φ mod 2π for the 8 phase terms, in double precision ──▶ uPhA, uPhB (vec4)
GPU (2560 × 1440 backing store)
[shadow] light presets only
same mesh; the VS slides every vertex along the light onto a backdrop plane;
coverage fades with height above it; MAX blend ──▶ SH RGBA8 640 × 360
2 × (horizontal + vertical) 9-tap Gaussian ──▶ SH
[ribbon] 385 × 65 grid = 49,152 triangles, one drawElements, depth-tested, double-sided
VS surf(u, v) = centre(X) + across(θ)·v·width + billow·normal(θ)
θ = twist·πX/3.6 + fold·sin(1.25X − 0.9φ + …) + wake.twist(X)
wake read with a 2-tap cubic B-spline; normal = cross of two finite differences
FS palette(X/3.4 + drift) ▸ wrap diffuse ▸ Kajiya-Kay sheen ▸ fold glow (1 − |N·V|)³
▸ filaments: f = v·N, N = min(count, ribbon width in device px / 4.2),
coverage = 1 px box ∩ W px line, measured with |∇f|,
fading to the pattern's mean once the period drops under 3.6 px
──▶ MS 2560 × 1440, 2× MSAA at DPR ≥ 1.5 (4× at DPR 1) + DEPTH16
RGBA16F on dark pages, SRGB8_ALPHA8 on light ones
premultiplied: cleared to 0, alpha = coverage
[resolve] blitFramebuffer ──▶ scene same format 2560 × 1440
[depth blur] 13-tap downsample × 4 ──▶ D1 … D4 RGBA16F 1280 × 720 … 160 × 90
[bloom] dark presets only
soft-threshold 13-tap from D1 ──▶ B RGBA16F 640 × 360 … 80 × 45
3 × tent upsample, additive ──▶ B 640 × 360
[composite] ──▶ canvas 2560 × 1440
blur level = 4 · blur · band(distance along the projected ribbon axis)
▸ bicubic blend of the two nearest D levels
▸ + backdrop (page, shadow, vignette) × (1 − coverage) ▸ + bloom
▸ hue-preserving shoulder (dark) ▸ sRGB encode
▸ calm zone behind the HUD title and eyebrow (dark) ▸ TPDF dither
The ideas that matter
- A ruled sheet around a curve. Every point is a centre curve plus an across-vector
(0, cos θ, sin θ)times the width coordinate. At θ = 0 the sheet faces the camera; at θ = π/2 it is edge-on. Twist sets how fast θ advances along the ribbon, and fold amplitude is a travelling wave on θ, so the folds roll along the ribbon instead of sitting still. Everything along the length is a function of the local axis coordinate X in world units rather than of the mesh's u, so a 21:9 monitor shows more ribbon, not a stretched one. - Constant-width filaments. The filaments are iso-lines of f = v·N.
|∇f|(fromdFdx/dFdy) is the number of periods per pixel, so the distance to the nearest line in pixels is|fract(f + ½) − ½| / |∇f|. Coverage is the exact overlap of a one-pixel box with a line W pixels wide, so lines stay W pixels wide however foreshortened the sheet is. Once the period falls below about 3.6 px the pattern can't be resolved, and the shader cross-fades to its mean, W·|∇f|, which is what a perfect filter would return. There is no moiré at any count from 30 to 800. Filament count is a ceiling: the count is capped so the face-on ribbon keeps at least 4.2 device pixels per period. On a 1x screen at 1280 × 720 the ribbon is about 374 px wide, so 150 filaments become 89 real hairlines rather than a faint striation. The cap uses the ribbon's width at the z = 0 plane, not its per-frame projection, so the lines don't swim as the ribbon drifts toward and away from you. - Compression is the fold. Because the width is constant and the spacing is not, filaments crowd together wherever the sheet turns away from you. On white the grooves merge into a pale seam, and in Mono the graphite hatching darkens exactly as a pencil drawing shades a fold. The fold glow adds
(1 − |N·V|)³on top, using real finite-difference normals (three evaluations of the surface per vertex). That is steadier than the screen-derivative trick, which is quantised to 2×2 pixel quads. - Silhouettes need MSAA, not shader AA. Where the sheet passes in front of itself, the fold edge is a real geometric silhouette. Derivative tricks can't anti-alias it, and blended fringes on a depth-tested mesh leave halos. The scene is drawn into a multisampled target with a depth buffer and resolved with
blitFramebuffer. The fragment shader still runs once per pixel; only coverage is supersampled. The sample count follows the density: 2× at DPR ≥ 1.5, which is already 8 coverage samples per CSS pixel on a retina screen, and 4× only at DPR 1. The format follows the theme. Only the dark theme has HDR content, so only it pays for RGBA16F. The light themes never leave 0…1 and use SRGB8_ALPHA8, which has half the bytes and a perceptual encoding that doesn't band. - The backdrop lives under the coverage. The scene is premultiplied: it is cleared to zero and the ribbon writes alpha 1, so after the resolve the colour is coverage × ribbon and alpha is the coverage. The composite adds shaded backdrop × (1 − coverage), so the cast shadow and the vignette never touch the ribbon or its antialiased edges, the blur levels composite correctly at soft edges, and no full-screen pass is spent on the multisampled target.
- Colour is authored, in Oklab. A 256 × 32 RGBA16F ramp is generated in JS from each palette's stops, interpolated in Oklab (with a smoothstep hold on each stop) and given a painterly warp across the width. Oklab keeps pink-to-orange and violet-to-blue transitions saturated where linear RGB goes muddy. The back face reads the ramp 0.21 further along, so a twist shows a colour change across the fold.
- Satin, not plastic. The highlight is Kajiya-Kay:
(1 − (T·H)²)40, which issin(T, H)80, with T along the fibres. It stretches the sheen across the filaments the way it sits on brushed satin, and slides as the sheet twists. - Depth of field along the ribbon, not along the screen. The blur level grows with distance along the ribbon's projected axis from its centre, so the ends dissolve on portrait phones as well as on landscape monitors. With the default camera yaw the near end swings toward you and goes soft first. Levels come from a 13-tap downsample chain and are read with cubic B-spline taps, so even the 1/16 level upsamples without blocks.
- The cursor is an obstacle in a one-dimensional wave medium. The CPU projects the ribbon's centre line (the same function as the shader) to the screen and pushes each of 128 cells away from the cursor. Crossing the ribbon also drags and twists it in proportion to the speed across. Two damped wave equations carry the disturbance away along the ribbon at 1.15 world units per second, and a weak spring pulls it home. Most of the response goes into twist, because a rolling fold is what the eye tracks. The twist's footprint along the ribbon is 1.8× wider than the push's, so a crossing launches one broad roll rather than a tight kink that disperses. Its restoring frequency is low (1.1 rad/s, damping 0.7 /s), so the roll eases back over about 3 s with no spring-back. A brisk crossing at the default Cursor bend rolls the sheet about 1.5 rad, and a fold travels several hundred pixels down the ribbon before it settles. The twist depends on how far you move across the ribbon, not how fast. For about 1.5 s after a crossing, the ambient drift slows to 70% so it doesn't compete with the wake. The wake is read in the vertex shader through a cubic B-spline, because bilinear interpolation would crease the normals at every cell boundary. A resting mouse keeps its gentle bend; a lifted finger lets go after 0.6 s.
- Refresh-rate independent, measured. The spring and both wave equations integrate in the same ≤ 1/240 s substeps. Running the page's own simulation over the same 2.5 s ghost stroke, the final fields differ from 120 Hz (relative RMS over all 128 cells) as follows. Bend: 2.1% at 60 Hz and 6.1% at 30 Hz. Twist: 0.9% and 3.0%. 144 Hz agrees to 0.1%. The remainder comes from the pointer and the forces being sampled once per frame.
- Precision on long-lived tabs. The ambient phase φ only grows, and after a day it would be about 39,000. As a float32 uniform that is about 0.004 rad per step, enough to make the hairlines shimmer. Instead, the CPU computes each of the vertex shader's eight phase terms k·φ mod 2π in double precision and uploads them as two
vec4s, so the GPU only ever sees angles in [0, 2π). The CPU mirror of the centre curve uses the same φ, so the two stay in step. - Light and dark are different composites, not a colour swap. On light pages the filaments mix toward the palette's line colour, folds mix toward a pastel of the local hue, distant parts fade into the page, and a coloured shadow sits underneath. On dark pages the sheet is dimmed to 16–42%, filaments and folds add HDR light in the local hue, a soft-thresholded mip chain blooms them, and a hue-preserving shoulder lets the hottest folds drift toward white instead of clipping into a hue shift.
- No banding, no haze. The blur and bloom chains are RGBA16F. The light scene is SRGB8_ALPHA8, whose steps are perceptually even, and its 13-tap downsample averages to sub-step precision. The composite ends with triangular-PDF dither after the sRGB encode. The copy keeps a soft scrim of the page colour behind it.
- The HUD stays legible on dark pages. The ribbon's warm far end often passes through the top-left corner, behind the family chip and the hero eyebrow, which are drawn in 66% and 40% white. On dark pages the composite measures both labels' text extents at every resize and treats each as a short segment. Within about 0.3 screen heights of either segment it mixes the frame 70% toward the backdrop. It does this in display space, after the tone shoulder, so even a blazing fold keeps only 30% of its contrast there. Mixed in linear HDR, the same 70% would barely dim a fold at 5× white. Together with the calm band along the top edge, the far end reads as receding into shadow.
Parameters
Presets
Performance & compatibility
- Measured (harness, 1280 × 720 @2x = 2560 × 1440 backing store, Apple M-series GPU, Chrome): 60 fps through the scripted sweep (frame-time p95 16.7 ms, no frame over 25 ms), with about 0.1 ms of JS per frame. The final full harness run measured 3.96 ms mean / 5.87 ms p95 of GPU per frame for the default preset. Across six harness runs of this build the readings were 2.4–5.7 ms mean and 4.8–9.8 ms p95. These are upper bounds, not an idle measurement. Two to five other builds were running their own harness sessions on the same GPU throughout, and no idle window appeared in more than ten minutes of waiting for one.
- Before and after this round’s changes, under identical contention: the previous build and this one, open in the same browser, measured in alternating 2 s windows over six rounds, with the inactive page paused off-screen. Median of the window medians, with the lowest 10th percentile in brackets: Stripe 2025 6.9 → 5.8 ms (3.4 → 2.9) · Night 6.3 → 4.8 ms (2.3 → 2.0) · Mono 5.0 → 3.5 ms (1.9 → 1.3). The best single windows for this build were 3.7, 3.0 and 1.6 ms. It is cheaper on every preset. Mono runs the same passes as Stripe 2025, so the gap between those two is a measure of the noise.
- What scales it: bandwidth, not geometry. Render targets at 2560 × 1440 now total 73 MB on the light presets: the 2× SRGB8_ALPHA8 colour target (29.5 MB), 2× 16-bit depth (14.7 MB), the resolve target (14.7 MB), the RGBA16F blur chain (9.8 MB) and small bloom and shadow targets. The dark preset uses 117 MB, because its 2× RGBA16F colour target is 59 MB. The previous build held 191 MB in every preset with 4× RGBA16F, of which the colour target alone was 118 MB. At DPR 1 the page keeps 4× MSAA, on a quarter of the pixels. The mesh (25,025 vertices) and the CPU wake (128 cells, about 0.1 ms of JS) are negligible. Depth blur at 0 skips the downsample chain, and Bloom and Cast shadow are skipped entirely on the themes where they don't read; their labels say so.
- Mobile: In the harness's 390 × 844 touch emulation (DPR 3, canvas capped at 2×, so 780 px wide) touch-drag ran at about 55 fps, with no horizontal overflow, and the controls sheet fits (8–382 px). That emulation runs on the desktop GPU, so it is not a phone measurement. On portrait screens the ribbon runs steeper (about 55°), sits higher, above the copy, and narrows by 30%. Touch devices and the gallery embed use a 257 × 49 grid. A finger drag bends the ribbon, and lifting it lets the ribbon go.
- Reduced motion: the page simulates 2.5 s of the ghost stroke on the CPU (spring and wake only) and renders a single frame; nothing animates until “Play anyway”, and the cursor hint stays hidden until then, because the still can't respond. The page is ambient: it drifts while visible, and the harness measured 0 frames rendered while it was scrolled off-screen.
- Requirements: WebGL2 is the only hard requirement; without it the page shows its poster and a message.
EXT_color_buffer_floatis optional. With it, dark pages render HDR into RGBA16F. Without it, every target is SRGB8_ALPHA8: the light presets look identical, and Night stores its scene at half scale, so the folds clip at 2× white and the bloom is reduced. This path was tested by hiding the extension, and all three presets ran with no GL errors. If the GPU offers no multisample count, the page renders with a single sample. That was tested by forcing samples = 0: fold silhouettes show one-device-pixel stair-steps, and everything else is identical. There are no textures, fonts or network requests: the palette is generated at load.
References & credits
- Studied look: the stripe.com homepage hero (“single-wave”), described from its production bundle in
research/gradient-mesh.md. It uses a twisted plane, a palette image looked up by UV,sin(u·N)lines with a derivative-scaled threshold, fold glow from UV derivatives, a band blur and dither. https://stripe.com (proprietary). This page is an independent, from-scratch implementation in plain WebGL2; it contains none of Stripe's code or assets and is not affiliated with Stripe. The preset name describes the look being studied. - Björn Ottosson, “A perceptual color space for image processing” (2020), https://bottosson.github.io/posts/oklab/: the published Oklab matrices used to build the palette ramps. The post's reference code is public domain, with an MIT option. Only its matrix constants are used here; the conversion code is written fresh.
- J. Kajiya & T. Kay, “Rendering Fur with Three Dimensional Textures”, SIGGRAPH 1989, https://doi.org/10.1145/74334.74361: the anisotropic fibre highlight behind the satin sheen. Technique only, no code copied.
- J. Jimenez, “Next Generation Post Processing in Call of Duty: Advanced Warfare”, SIGGRAPH 2014, https://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare/: the 13-tap downsample and the tent upsample used for the blur levels and bloom. Technique only, no code copied.
- C. Sigg & M. Hadwiger, “Fast Third-Order Texture Filtering”, GPU Gems 2 ch. 20 (2005), https://developer.nvidia.com/gpugems/gpugems2/part-iii-high-quality-rendering/chapter-20-fast-third-order-texture-filtering: cubic B-spline filtering from bilinear taps (the wake in the vertex shader, the blur and bloom levels in the composite). Technique only, no code copied.
- M. Jarzynski & M. Olano, “Hash Functions for GPU Rendering”, JCGT 2020, https://jcgt.org/published/0009/03/02/: the pcg3d hash for the dither noise. Its constants are as published in the paper, and the function is written from the paper's description. Per-filament brightness uses the “lowbias32” integer hash constants from C. Wellons' hash-prospector, https://github.com/skeeto/hash-prospector (Unlicense, public domain).
- M. Gjøl, “Banding in Games: A Noisy Rant”, https://www.loopit.dk/banding_in_games.pdf: the triangular-PDF dither after display encoding, fading to uniform near 0 and 1. Technique only, no code copied.
- Technique notes, pitfalls and the candidate brief:
research/gradient-mesh.mdin this library (twisted ribbon sheet, filament-wave candidate, dithering).