How it was built

Live trading UIs on clickable 3D screens

Every screen on the trading floor is a real AG Grid table, an ECharts chart or a plain HTML panel. They tick with live (simulated) data, sit in a WebGL room, and still take clicks, typing and scrolling, even at an angle. This page explains how, using Chrome's HTML-in-Canvas API (stable since Chrome 157).

The problem

WebGL can't render DOM. Until now, putting a data grid inside a 3D scene meant one of three compromises: rasterise the DOM with a screenshot library (slow, lossy, no interaction), float CSS-transformed HTML above the canvas (no depth, no lighting, no post-processing), or rebuild the grid from scratch in WebGL (and lose everything AG Grid gives you).

HTML-in-Canvas removes the compromise. A canvas declared with content="drawable" lays out its child elements like normal DOM, never shows them directly, and lets you draw them into the canvas, including into a WebGL texture. You also tell the browser where each element ended up on screen, so hit testing and accessibility follow it.

The architecture

Data flows from the DOM panels to WebGL textures; clicks flow back through a projection matrix DOM panelsAG Grid · ECharts (SVG)order ticket · risk controlschildren of<canvas content="drawable"> WebGL texturesone per paneltexElementSubImage2D()throttled by distance,skipped when off screen Three.js roomExternalTexture on planesreflective floor, neonbloom → sRGB outputcamera you walk with paint sample Hit-test geometryupdateElementGeometry()one perspective matrix per panel,recomputed when the camera moves camera · plane pose clicks, keys, hover
Pixels flow left to right every time a panel repaints; input flows back through a matrix that maps each panel to where it is drawn.
Step 1

Put the UI inside the canvas

The WebGL canvas opts in with content="drawable". Each panel (an AG Grid, an ECharts chart, the order ticket) is appended to it with the drawable attribute. They keep real layout, styles, focus and events; they're just not displayed until you draw them.

<canvas id="floor" content="drawable"></canvas>
const panel = document.createElement('section');
panel.setAttribute('drawable', '');
panel.style.width = '1440px';
panel.style.height = '810px';
canvas.appendChild(panel);
createGrid(panel, gridOptions);   // a normal AG Grid

Charts use ECharts' SVG renderer, so a chart is ordinary DOM inside its panel and gets captured like everything else.

Step 2

Upload only what changed

When a drawable child repaints (a ticking cell, a cell flash, a chart redraw), the canvas fires a paint event listing exactly which elements changed. We mark those dirty and upload them in the render loop with gl.texElementSubImage2D into a texture we own, wrapped in Three.js's ExternalTexture.

canvas.addEventListener('paint', (e) => {
  for (const el of e.changedElements) surfaces.get(el).dirty = true;
});

// every frame, for dirty panels that are visible and due an update:
const { width, height } = canvas.getElementImageDefaultSize(el);
gl.bindTexture(gl.TEXTURE_2D, tex);              // texStorage2D'd at that size
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);    // match Three's UV convention
gl.texElementSubImage2D(gl.TEXTURE_2D, 0, 0, 0, el);
gl.generateMipmap(gl.TEXTURE_2D);
renderer.resetState();                           // we changed GL state behind Three

Uploads are throttled by distance (about 12 Hz near, 6 Hz mid-room, 3 Hz far, every frame for the screen you are using). A panel that is out of view stays dirty and uploads when you turn around. Charts also skip their own redraws while hidden. The ticker ring is one long strip scrolled with a UV offset, so scrolling costs no uploads at all.

Step 3

Make it clickable in 3D

Drawing an element into a texture doesn't tell the browser where it is. For that, each frame we give the canvas a transform that maps the element's CSS pixels to where its 3D plane lands on screen. Because the panel is a flat rectangle, that mapping is exactly one 4×4 projective matrix (the same thing a CSS matrix3d() is):

// element CSS px → plane-local metres → world → clip → canvas CSS px
const toPlane = new Matrix4().set(
  pw / W, 0,       0, -pw / 2,
  0,      -ph / H, 0,  ph / 2,
  0,      0,       1,  0,
  0,      0,       0,  1);
const toCanvas = new Matrix4().set(
  cw / 2, 0,       0, cw / 2,
  0,      -ch / 2, 0, ch / 2,
  0,      0,       1, 0,
  0,      0,       0, 1);
const m = toCanvas.multiply(camera.projectionMatrix)
  .multiply(camera.matrixWorldInverse)
  .multiply(mesh.matrixWorld)
  .multiply(toPlane);

canvas.updateElementGeometry(panel, {
  canvasTransform: DOMMatrix.fromFloat64Array(new Float64Array(m.elements)),
});

The perspective divide happens in the browser, so the mapping is exact at any angle: elementFromPoint, getBoundingClientRect, hover, focus and real mouse clicks all follow the projected panel.

A cheaper affine approximation (a 2D matrix fitted to three corners) is not good enough. With a 400×300 panel of nine buttons, the exact matrix hit all nine at every angle we tried, while the affine fit hit 8, 6 and 4 of them at 30°, 50° and 65°, with the far corner off by 130, 211 and 260 px.

Two edge cases need handling. If any corner falls behind the camera (w ≤ 0), the projection folds: Chrome reports a bounding box thousands of pixels tall and the panel stops taking clicks, even its visible part. Those panels get clearElementGeometry() instead. And where panels overlap on screen, Chrome 158 stacks them in the order they first received geometry; later updates and clears never reorder them. So the demo sets the order once at startup, wall screens first and desk monitors last, because monitors are what stand in front of walls.

Step 4

Walk, then use a screen

You walk with pointer lock (WASD and mouse-look). Clicking a screen flies the camera onto its normal and releases the cursor, and from then on you use the grid or ticket directly. The camera distance is chosen so that one CSS pixel of the panel maps to one screen pixel:

distance = planeHeight × viewportHeight / (2 · tan(fov / 2) · targetPixelHeight)

Text is as sharp as on a flat page, and drag gestures (column resize, sliders, scrollbars) move 1:1 with the mouse. The targetPixelHeight is capped so a large panel still fits on a small window.

Step 5

Lighting that never blurs text

The room renders into a half-float target, then through an Unreal bloom pass, then to sRGB. Neon strips, light bars and the floor grid are deliberately HDR (values above 1.0), so they bloom. Panel screens are drawn with an unlit shader that converts the texture's sRGB bytes to linear and scales them to at most 0.86, below the 0.9 bloom threshold. They never glow, and their colours come out exactly as in the DOM. The world-clock board hanging over the desks is the one exception: boosted to 1.12 so its digits glow but stay legible.

Bloom also eases off while you're using a screen, so nearby neon never haloes over a table. Room accents follow a mood: they drift green or magenta with the desk's P&L, and pulse red while the kill switch is engaged.

What we verified in Chrome 158

Runtime probes and the end-to-end smoke test established these behaviours, which the docs don't spell out:

BehaviourObserved
getElementImageDefaultSize() before the first paintThrows: “No cached paint record for element”
Image sizeCSS size × canvas pixel ratio (a 1280×720 panel is 2560×1440 at DPR 2)
texElementSubImage2D outside the paint handlerWorks; uploads the latest paint record
UNPACK_FLIP_Y_WEBGLRespected
canvasTransform originThe canvas's top-left corner; the element's own layout position is ignored
Perspective (non-affine) matricesAccepted; hit testing and getBoundingClientRect follow them
A corner behind the camera (w ≤ 0)Bounding box blows up; the element takes no clicks at all
Hit-test stacking of overlapping drawablesFixed by the order elements first got geometry; later updates, clears and preserveHitTestOrder don't change it
SVG and elements larger than the canvasCaptured in full

Budget

Append ?dpr=1 for the lightest load, ?dpr=2 for full retina, or ?fx=low to drop reflections and bloom.

Gotchas along the way

Tested end to end

npm run smoke starts the app in real headless Chrome and drives it with real mouse and keyboard input through the 3D projection. It checks that every panel uploads, clicks a Market Watch row, types a quantity and presses BUY, sends a SELL limit order from the full ticket, cancels it from My Orders, and engages and resets the kill switch.

Stack

Three.js · AG Grid Community · Apache ECharts (SVG renderer) · TypeScript · Vite · Puppeteer for the smoke test. Market data, orders and positions are simulated in the browser; nothing connects to a real market.

Walk the floor

Open the demo in Chrome 157 or later on a desktop or laptop. Use WASD to walk, and click any screen to use it.

Open the demo