Head-tracked 3D portal

I wanted to see if FaceDetector and BarcodeDetector could drive an asymmetric off-axis 3D frustum (the Johnny Chung Lee desktop-VR window) and pin live HTML onto a tilted QR code over a camera feed, while updateElementGeometry() keeps every button and input clickable as the perspective changes. Drag across the box below to shift the virtual eye, or tap a tracker mode to try tilt, webcam face tracking or AR barcode pinning.

z +0.15 Pop-out strip
z -0.35 Mid-room form
0 pulses
z -0.85 Window A
Eye
(0.00, 0.00, 2.60)
Frustum
L -0.06 R 0.06 B -0.04 T 0.04
Source
pointer drag
Last hit
none (0 total)
Deep back plane
AR pin synthetic qr
https://html-in-canvas.page/vision-portal/
Taps: 0
starting...

Drag empty space in the box to move the virtual eye. Click buttons, type into the mid-depth form or switch palettes directly inside the 3D scene. Camera modes only ask for permission after you tap them, and every camera track stops when you switch back or leave the page.

Show the code off-axis frustum, projective hit boxes, Shape Detection APIs and ElementGL rendering
  1. Four live drawable HTML cards inside one canvas. Three depth layers (foreground strip at z = +0.15, mid-room form at z = -0.35, deep readout at z = -0.85) and one AR marker tag share a single <canvas content="drawable" layoutsubtree>.
  2. Asymmetric off-axis frustum from the virtual eye. Projecting the screen edges at z = 0 onto the near plane pins the window border to the canvas while shifting cards behind the glass with the eye and cards in front of the glass against it.
  3. Projective updateElementGeometry() for 3D layers and 4-corner AR quads. Each card's element-to-canvas 4×4 matrix (or 4-corner barcode homography) is scaled by geometryUnit() and paired with a dataset.hitTick toggle so Chromium clears its hit-test cache.
  4. On-tap FaceDetector and BarcodeDetector polling. Camera access starts only on a button tap, keeps at most one detection call in flight per frame, never reads pixels with getImageData(), and stops every track on mode change or pagehide.
  5. One WebGL 2 context through ElementGL. Dirty HTML children upload via stage.upload(el) (gl.texElementSubImage2D()), while companion shaders on stage.gl draw the anti-aliased grid room, camera video feed or synthetic QR marker.

How it works

An off-axis projection treats the canvas itself as a physical glass pane at z = 0. When the virtual eye moves to (ex, ey, ez), the view matrix translates the world by (-ex, -ey, -ez) without rotating the camera, and the frustum bounds (left, right, bottom, top) shift asymmetrically so the four corners of the glass stay pinned to the four corners of the canvas. Because of that shear, the back walls and the cards at z = -0.35 and z = -0.85 shift behind the frame, while the foreground strip at z = +0.15 shifts the opposite way and appears to sit in front of the glass.

Everything draws on one WebGL 2 context created with new ElementGL(canvas, ...) from /lib/element-gl.js. Whenever a control inside any card changes, Chromium fires a paint event on the canvas and I upload only the dirty elements with stage.upload(el) (gl.texElementSubImage2D()). Before drawing the cards back-to-front with stage.quad(), a companion shader on stage.gl draws either the recessed perspective grid room or, in AR barcode mode, the live camera <video> texture (or a procedural tilted QR target when no camera or BarcodeDetector is available).

For hit testing, each visible card gets a 4×4 projective DOMMatrix mapping its CSS pixels into canvas coordinates. In portal mode that comes from M_ndcToCss * VP * M_elemToWorld; in AR barcode mode it comes from a closed-form projective homography fitted to the barcode's four cornerPoints. I scale the matrix by geometryUnit() from /lib/surface.js for HiDPI screens, pass it to canvas.updateElementGeometry() and toggle dataset.hitTick whenever the matrix moves. Cards that aren't active in the current mode get inert = true and move off-canvas so they don't intercept clicks or Tab focus.

Both Shape Detection APIs stay idle until you tap Camera face or AR barcode. Because reading pixels back with getImageData() in a frame loop loses 2D canvases on Android Chrome, this page never runs a pixel-readback fallback tracker. If FaceDetector or BarcodeDetector isn't exposed in your browser (many desktop builds need chrome://flags/#enable-experimental-web-platform-features), the status line says so directly and you can still test the off-axis portal with pointer drag, auto sweep or device tilt, and test 4-corner perspective pinning with the built-in synthetic QR target.

Live checks

ResultCheckDetail

Findings