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.
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
- Four live
drawableHTML cards inside one canvas. Three depth layers (foreground strip atz = +0.15, mid-room form atz = -0.35, deep readout atz = -0.85) and one AR marker tag share a single<canvas content="drawable" layoutsubtree>. - Asymmetric off-axis frustum from the virtual eye. Projecting the screen edges at
z = 0onto 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. - 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 bygeometryUnit()and paired with adataset.hitTicktoggle so Chromium clears its hit-test cache. - On-tap
FaceDetectorandBarcodeDetectorpolling. Camera access starts only on a button tap, keeps at most one detection call in flight per frame, never reads pixels withgetImageData(), and stops every track on mode change orpagehide. - One WebGL 2 context through
ElementGL. Dirty HTML children upload viastage.upload(el)(gl.texElementSubImage2D()), while companion shaders onstage.gldraw 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
| Result | Check | Detail |
|---|
Findings
- Off-axis projection pins the glass border while shifting every depth plane. Projecting the glass edges
(-halfW - ex, halfW - ex) * (near / ez)holdsz = 0fixed on the canvas edge while producing opposite parallax directions forz = +0.15andz = -0.85. - One
DOMMatrixpath covers both 3D frustum cards and 4-corner barcode quads. Both the off-axisVP * M_elemToWorldprojection and the closed-form 4-corner homography output a 4×4 column-major matrix that drives bothElementGL.quad()andupdateElementGeometry(). - No pixel-readback loop for camera tracking. Avoiding
getImageData()inrequestAnimationFrame()keeps the page within the mobile GPU rules, while reporting Shape Detection availability plainly whenFaceDetectororBarcodeDetectorisn't enabled. - Browser verification status. Syntax and graphics source checks pass locally; live execution in Chromium 157, desktop webcam
FaceDetectorand AndroidBarcodeDetector/DeviceOrientationEventare not verified yet (seefindings/vision-portal.md).