TechniquesA 3D stage locked to CSS pixels
A shift-lens camera for a three.js canvas behind the DOM.
What it costs a frame
- GPU
- 0.46 ms
- CPU, median
- 0.27 ms
- CPU, 95th pct
- 0.44 ms
- Draw calls
- 16
- Weight
- Light
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 0.37–0.63, CPU 0.25–0.38 ms). What ran: Five extruded bars, a shelf and a hall with grid lines, a 2048 shadow map; the eye drifts round a slow loop as if the pointer moved, so every frame redraws. At rest nothing is drawn. Phones: tiers are being measured next.
| Machine | GPU ms | CPU ms | CPU p95 |
|---|---|---|---|
| RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900Hreference · measuring tool | 0.46 | 0.27 | 0.44 |
| apple · Apple A19 Proin a browser tab · 16 November 2026 | 1.95 | 0.32 | 0.46 |
| Intel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258Vin a browser tab · 15 November 2026 | 1.83 | 0.67 | 0.88 |
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 ?
- 7.30 ms
- 1% low ?
- 76 fps
- Varies by ?
- ±1.88 ms
All metricsIntel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258V · in a browser tab
Frames run back to back, each starting once the GPU has finished the last, so frame times show the work itself. They have a floor of about 4–5 ms from the browser’s own scheduling: GPU and CPU ms stay the measure of cost.
Frames
- Median (p50) ?
- 7.30 ms
- p95 ?
- 9.22 ms
- p99 ?
- 9.88 ms
- Slowest ?
- 19.69 ms
- Mean ?
- 6.86 ms
- Standard deviation ?
- 1.88 ms
- 1% low ?
- 76 fps
- 0.1% low ?
- 51 fps
- Hitches ?
- 2 of 600
- Over budget ?
- 2 of 600
Main thread
- Long tasks ?
- 0
- Long frames ?
- 0
- Event-loop delay ?
- 0.1 / 0.9 / 1.1 ms
Input
- Interactions ?
- 490
- Input to paint ?
- 4.9 ms, worst 9.2
- Longest handler ?
- under 16 ms
Memory
- JavaScript heap ?
- 83.9 → 84.5 MB
- Growth ?
- +0.56 MB
What it needs
- Renders with
- WebGPU or WebGLWebGPU where there is one, WebGL2 where there is not.
- Your browser
- Runs hereNo WebGPU needed
- Depends on
- three.js r187No other packages
What it’s for
- 3D bars and solids that sit exactly on a DOM chart
- Objects placed in slots of a CSS layout
- A page that opens onto a space behind it
- Pointer parallax without the layout swimming
- Labels in the DOM, geometry on the GPU
- A push-in toward what someone pressed
Pitfalls, in brief
- Never turn the camera to look at the page: the picture plane tilts and z = 0 is keystoned (the demo’s ordinary camera is off by several pixels, more the further the eye stands from the middle).
- Units are CSS pixels and world y is down-negative: world (x, −y, 0) is CSS (x, y).
- Read the DOM boxes again after every layout change (a resize, a reflow, a font loading, a CSS transition), in the stage’s own coordinates (rectOf subtracts the host’s rect).
- The near plane must stay in front of z = 0 (it is 0.35 of the eye’s distance) and the eye must be in front of the page.
- The eye’s distance sets the strength of the perspective: about twice the stage height reads as a calm one-point view.
3 more in brief
- A camera from the page’s own setup (a harness, a framework) may reset aspect or the projection on resize: re-apply the lens after it (resize() does).
- Something at depth z looks smaller: scale it by grow(z) to fit a DOM well, and place it with at(x, y, z) for the eye at rest.
- Draw on demand: with the eye at rest and nothing laid out again, skip the frame. step() returns false once the drift has settled.
Where it comes from
From HaTac. Fully custom code.
Robert Kooima, Generalized Perspective Projection (2008): The off-axis frustum for an eye off the screen’s centre, which a view offset on a symmetric frustum gives here.
The shift (rise and fall) movement of a view camera: Keeping the picture plane parallel to the page and shifting the lens, so parallel lines stay parallel and the page is undistorted.

