Feature Library

A gravitational lens behind the page

2.78 GPU · 0.41 CPU ms
A still of the A gravitational lens behind the page demo
Still
The live demo starts when it’s in view.Drag the sky to turn it · point at a card to make it heavier, or throw it · click the sky for a wave, a body or a row to pick it

Elements on the page are masses that bend a procedural deep sky behind them.

What it costs a frame

2.78 ms
0.41 ms
GPU
2.78 ms
CPU, median
0.41 ms
CPU, 95th pct
0.58 ms
Draw calls
0
Weight
Heavy

Measured 13 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 157, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged GPU 2.72–3.12, CPU 0.41–0.47 ms). What ran: Six bodies on Kepler orbits round the black hole (photon march, disk, photon ring), three card lenses and the table panel as glass, the fabric on, the camera turning slowly and a wave every two seconds; at the stage’s size and pixel ratio, timed with its own timestamp queries. Phones: tiers are being measured next.

On every machine it was measured on
MachineGPU msCPU msCPU p95
RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900Hreference · measuring tool2.780.410.58
apple · Apple A19 Proin a browser tab · 16 November 20268.071.381.68
Intel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258Vin a browser tab · 15 November 20265.440.821.14

Bars against one 16.7 ms frame. A browser-tab run is timed in a visible tab without the tool’s scripted input, so read it as close, not exact.

How steadily it runs on Intel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258V · in a browser tab

Typical frame ?
16.68 ms
1% low ?
56 fps
Varies by ?
±0.40 ms
All metricsIntel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258V · in a browser tab
p50p95p9916.03 ms17.95 ms +
How long each frame took. Most frames sit in the tall bars; a long tail to the right is hitching.

Frames run on a 60 Hz timer (a page demo), so most frames take about one tick, 16.7 ms: the spread around it is what matters.

Frames

Median (p50) ?
16.68 ms
p95 ?
17.45 ms
p99 ?
17.84 ms
Slowest ?
18.02 ms
Mean ?
16.71 ms
Standard deviation ?
0.40 ms
1% low ?
56 fps
0.1% low ?
56 fps
Hitches ?
0 of 600
Over budget ?
0 of 600

Main thread

Long tasks ?
0
Long frames ?
0
Event-loop delay ?
0.1 / 1.3 / 1.9 ms

Input

No input during this run. A browser-tab run plays none.

Memory

JavaScript heap ?
84.2 → 84.8 MB
Growth ?
+0.61 MB

What it needs

Renders with
WebGPUNeeds WebGPU: current Chrome and Edge, Safari 26+, Firefox 141+ on Windows.
Your browser
Checking…Looking for WebGPU
Depends on
NothingNo other packages

What it’s for

  1. A backdrop that answers the page: cards bend the sky behind them
  2. A hero section or splash that rewards pointing and throwing
  3. A data story where the total is a black hole and the parts orbit it
  4. Teaching lensing, Einstein rings and Kepler’s laws
  5. Frosted glass panels over a live GPU picture
  6. A space scene for a game menu or a loading screen

Pitfalls, in brief

  1. The page’s boxes bend the sky in screen space, the hole in three dimensions: the boxes first, then the hole.
  2. Mass from a box: a little for its size, more for its rest mass (absolute, so a heavy small card bends as far as a heavy big one), and up to its own size again for what it gains when pointed at or thrown.
  3. The march runs only inside a sphere of 10 rs round the hole (march), with a uniform step bound so the compiler does not unroll it; what the light bends before and after the sphere is added in closed form.
  4. Read every [data-mass] rect in the same frame you draw, from the canvas’s own top left: a rect read a frame early puts the glass a frame behind a thrown card. dom-masses does both; if you move masses yourself, call setMasses and setPanels every frame something moves.
  5. A [data-glass] element must be transparent: the GPU draws its glass under it.
9 more in brief
  1. Labels pinned to bodies must hide behind the hole: on screen inside its shadow and further from the eye than the hole.
  2. Rest when nothing moves: hold time and seed still, stop the orbit clock, and stop calling frame().
  3. frame() skips a frame while the last is still on the GPU (drawn false): draw again next frame or a change is lost.
  4. The paper look subtracts its lines and dust (reverse-subtract blending), so the same colours ink the page instead of lighting it; a light colour on paper needs its ink colour for anything drawn beside it (the demo’s inked()).
  5. Ripples, the dust and the glass edges are sized in CSS px and scaled by the pixel ratio; lowering the ratio to save time (the Resolution control) keeps them the same size on screen.
  6. On a weak GPU pass tier (LENS_TIER): it draws at a share of the pixel ratio you give resize, 0.85 at medium and 0.6 at low (about a third of the pixels), on top of any Resolution you chose.
  7. The canvas takes pan-y touches, so a vertical swipe still scrolls the page on a phone and only sideways drags turn the view.
  8. A WebGPU device can be lost (a driver reset, a sleeping laptop): frame() then returns null for good.
  9. The canvas is kept within the device’s largest texture (8192 px on most): a wider canvas (a 5K screen at a pixel ratio of 2) draws at a lower pixel ratio rather than failing.
14 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Fully custom code.

Karl Schwarzschild, On the gravitational field of a mass point (1916): The black hole: its radius rs, the photon sphere at 1.5 rs where the bright ring forms, and a shadow about 2.6 rs across (3√3⁄2).

Albert Einstein, Lens-like action of a star by the deviation of light in the gravitational field (Science, 1936): The weak-field deflection 4GM/c²b = 2 rs/b used outside the march, and the Einstein ring a source right behind a lens makes.

Riccardo Antonelli, Starless (a black hole raytracer) and its write-up: Marching a photon in flat coordinates under the force −(3⁄2) h² x / r⁵, which traces Schwarzschild null geodesics. Written here as a leapfrog step.

Johannes Kepler, Astronomia nova (1609): The orbits: Kepler’s equation M = E − e sin E, solved by Newton’s method on the CPU and the GPU.

J. M. A. Danby, Fundamentals of Celestial Mechanics (1988): The starting guess M + 0.85 e for Kepler’s equation.

Mark Jarzynski & Marc Olano, Hash Functions for GPU Rendering (2020): PCG3D, the integer hash behind every star, galaxy and speck of dust, and PCG for the grain.

Inigo Quilez, 2D distance functions: The rounded box distance (sdRR) that shapes the rims and the glass.

gravitational lensingblack holeschwarzschildeinstein ringkepler orbitsdom + gpuglassfrosted glassspacebackdropshowpiecedataraw webgpuwgslcomputeprocedural skyflingdraw on demandtimestamp queriesno dependencies

Near it in the frame