Cinema optical rack-focus across three depth planes

I wanted to know if one ElementGL WebGL 2 canvas could composite three overlapping drawable HTML planes at separate depths with variable-aperture golden-angle disc bokeh and cinema focus breathing. Tap any plane directly on the canvas, press Tab to move focus into a control, or use the focus buttons and aperture slider below.

FAR · z=0.0 Settings & telemetry
MID · z=0.5 Workspace Lens Card CUE 01
50MM · f/1.4
NEAR · z=1.0 READY

Starting canvas…

Show the code three drawable depth planes, spring optics, 24-tap disc bokeh shader, WebGL pipeline and hit-box sync
  1. Three staggered drawable planes in one canvas. Far settings sheet (#rf-bg), midground editable workspace card (#rf-mid) and foreground inspector toast (#rf-fg) sit inside one <canvas content="drawable" layoutsubtree>.
  2. Aperture Circle of Confusion, deterministic tMs spring and plane layout. Computes normalized defocus across f/1.4 to f/11, evaluates the damped spring at exact timestamps and keeps primary buttons uncovered on 412 px phones.
  3. 24-tap golden-angle Poisson disc bokeh shader. Uses a single sharp tap when uBlurPx < 0.25 and switches to linear-light 24-tap Vogel disc accumulation with specular bloom and premultiplied alpha feathering when out of focus.
  4. Single-context WebGL 2 compositing. Calls stage.begin() before uploading dirty planes inside paint with UNPACK_PREMULTIPLY_ALPHA_WEBGL = true, draws back-to-front directly to the default framebuffer and unbinds the VAO.
  5. Focus-breathing hit-box calibration. Syncs updateElementGeometry() with geometryUnit(), the 1 + 0.015 * coC breathing scale and dataset.hitTick so every control on all three planes stays clickable.
  6. Five-argument 2D and plain-HTML fallbacks. Draws the three depth planes with five-argument drawElementImage() without WebGL 2, or moves them into #plain-host on context loss.

How it works

I placed three separate drawable sections inside one <canvas id="rf-canvas" content="drawable" layoutsubtree> backed by one ElementGL WebGL 2 context. When you tap a plane, press Tab into one of its controls or pick a focal preset, a deterministic tMs damped-spring solver moves focusDepth smoothly between 0.0 (Far), 0.5 (Mid) and 1.0 (Near).

Inside the paint event listener, state.hasPainted flips to true, stage.begin() sets the viewport and backing store before any upload, and only dirty planes upload via gl.texElementSubImage2D() with gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL set to true and trilinear mipmaps generated via gl.generateMipmap(). Each frame draws directly to the default framebuffer (null) with zero offscreen FBO passes:

  1. Studio optical backdrop: draws a dark radial vignette with a subtle focus ring tied to uFocusDepth.
  2. Crisp active plane: when a plane's Circle of Confusion blur radius drops below 0.25 CSS px, FOCUS_FRAG samples LOD 0 with one unpadded texture tap so typography and inputs stay razor sharp.
  3. 24-tap golden-angle disc bokeh: defocused planes expand their quad by 26 CSS px and sample 24 golden-angle Vogel disc offsets at a mipmap LOD scaled to the Circle of Confusion radius in linear light, so bright pills, indicator LEDs and card corners feather smoothly into circular bokeh discs weighted by f/1.4 to f/11 without repeated text ghosts.

Out-of-focus planes also breathe outward by 1 + 0.015 * coC around their centres. syncPlaneGeometry() multiplies geometryUnit() by that same breathing matrix for each plane, writes canvas.updateElementGeometry() and toggles dataset.hitTick so clicks and text selection hit the right control across all three overlapping planes.

Live checks

These checks build isolated fixtures on testStage() when you press the button, leaving the stage above untouched.

ResultExperimentDetail

Findings

Measured in headless Google Chrome 160.0.8188.0 Canary (2026-11-27) at 412x915 (DPR 2.625) and 1040x900 (DPR 1). Real Chrome 159 on Android and npm run check:jank stay not verified.