DOM radiosity

I wanted to know if a WebGPU compute pipeline could take a live HTML texture straight from drawElementImageToTexture(), build a Jump-Flood distance field and run 2D Radiance Cascades global illumination with zero CPU readback. Type into the glowing word, toggle the lamps or drag the dark pillars to sweep coloured shadows across the stage.

Drag
Drag
Drag wall

Show the code upload, Jump-Flood SDF, 4-cascade Radiance Cascades and hit-testing
  1. One drawable HTML gallery inside the canvas. Bright glyphs and lit buttons act as emitters; dark opaque pillars act as occluders.
  2. Seed compute pass (WGSL). Reads the live HTML texture with textureLoad(), unpremultiplies alpha and writes emitter radiance and JFA seeds.
  3. Jump-Flood Algorithm (WGSL). Runs log2(N) passes to compute exact Euclidean distance to the nearest live glyph or occluder.
  4. 2D Radiance Cascades (WGSL). Marches 4 angular-spatial cascades (4, 16, 64 and 256 rays) against the JFA distance field and merges upper cascades bilinearly.
  5. Composite and hit-testing. Composites the native-resolution DOM texture over the lit floor and calls updateElementGeometry() so clicks and typing stay aligned.
  6. Live checks. Probes drawElementImageToTexture() usage flags, textureLoad() premultiplied alpha, compute shadow contrast and elementFromPoint().

How it works

Every interactive element in the gallery lives inside a single <div id="scene" drawable> child of the canvas. When you type a letter, toggle a lamp or drag a pillar, Chrome fires a paint event on the canvas and the page uploads the element's current picture to an rgba8unorm texture with GPUQueue.drawElementImageToTexture() (or gl.texElementSubImage2D() on the WebGL 2 route through ElementGL).

The GPU classifies every pixel directly from that live texture, with no DOM geometry readback in JavaScript. Transparent pixels (alpha < 0.14) are air. Bright pixels (max(r, g, b) > 0.38 after unpremultiplying) are emissive light sources. Dark opaque pixels (alpha > 0.45 and max(r, g, b) <= 0.38) are solid occluders. That means typed glyph strokes float in open air as light emitters, while the dark pillar boxes block rays and cast coloured penumbra shadows.

On WebGPU, four @compute stages run on a downscaled grid (up to 384 px on the long side, rounded to multiples of 16) before the full-resolution composite pass:

  1. Seed pass: reads domTex with textureLoad(), writes emitter colour and solidity to an rgba16float scene texture, and seeds the Jump-Flood coordinate buffer.
  2. Jump-Flood SDF: runs 9 ping-pong passes (step 256 down to 1) so every pixel stores the exact Euclidean distance to the nearest solid glyph or pillar.
  3. Radiance Cascades: runs 4 cascades from coarse to fine (256, 64, 16 and 4 angular bins at probe spacings of 16, 8, 4 and 2 grid cells), sphere-tracing each cascade's ray interval against the JFA distance field and bilinearly merging unoccluded rays from the cascade above.
  4. Resolve and composite: resolves cascade 0 into a smooth irradiance texture, feeds it back as indirect bounce on the next frame, and composites the crisp native-resolution DOM texture over the lit gallery floor.

After each draw, updateElementGeometry() keeps the hit boxes of the text input, lamp buttons and movable pillars aligned with their drawn positions, and toggling a data attribute clears Chromium's hit-test cache whenever a pillar moves. On browsers without a usable WebGPU device (including headless test browsers with software adapters), the page runs the same JFA and 4-cascade Radiance Cascades algorithm in WebGL 2 fragment shaders inside one ElementGL context, and falls back to 2D canvas or plain HTML if WebGL is unavailable.

Live checks

These checks run on isolated fixtures when you press the button, using the shared device from checkDevice(). They never touch or scroll the gallery above.

ResultExperimentDetail

Findings