Anamorphic projection

I wanted to know if I could project one live interactive HTML card from a virtual cinema projector across a five-step 3D staircase and gallery corner so that it snaps flat at the sweet spot, then fractures across every tread and riser when you orbit. At the same time I wanted to measure what happens to updateElementGeometry() when one DOM element spans twelve non-coplanar faces.

Drag the gallery to orbit around the stairs, or press a camera preset. Type into the red headline box, pick a colour swatch, drag the Type slider or press Invert while orbited to see your DOM changes bend across every step. Double-click or press Sweet spot to snap back to the projector's eye.

Show the code Projective texturing shader, ElementGL upload, exact plane homography and per-face raycast tracking
  1. One live drawable poster inside the canvas. The headline input, colour swatches, toggle buttons and range slider are ordinary HTML inside one <canvas content="drawable" layoutsubtree>.
  2. One WebGL 2 context through ElementGL. On every paint event, the poster uploads via gl.texElementSubImage2D() into a mipmapped anisotropic texture so text stays sharp when stretched across horizontal treads.
  3. Projective texturing across every stair tread, riser and wall. Each fragment transforms its 3D world position by the fixed projector matrix uProjVP to find its poster UV. When the viewer camera matches the projector, depth cancels out and every face snaps into one flat rectangle.
  4. Exact 4x4 homography for updateElementGeometry(). Intersecting the projector ray for element pixel (ex, ey) with any 3D plane N . X = d is linear in homogeneous coordinates, so one DOMMatrix matches any single face (and all twelve faces at once at the sweet spot).
  5. Per-face raycast tracking when orbited. In Track pointer face mode, each pointer move raycasts the five risers, five treads, left wall, back wall and floor, then swaps updateElementGeometry() to the hit plane so buttons stay clickable off-axis.

How it works

A physical anamorphic mural (like Felice Varini's architectural installations) paints a single flat drawing from one vantage point onto every surface the projector rays touch. Here a fixed virtual camera at (1.55, 2.05, 2.75) acts as the projector. Its view-projection matrix uProjVP is passed into the fragment shader for the entire 3D gallery mesh: five concrete stair treads, five risers, a stepped side cheek, the left wall, the back wall and the floor.

For every shaded pixel at world position X, the fragment shader computes clip = uProjVP * vec4(X, 1.0) and samples the live HTML texture at (0.5 + 0.5 * clip.x / clip.w, 0.5 - 0.5 * clip.y / clip.w). Because the staircase rises monotonically away from the projector and sits above the floor, none of the visible faces shadow another from the projector's eye. When the viewer camera shares the projector's eye position and target, the camera-space depth z divides out identically in both matrices, so the projected webpage collapses into an axis-aligned rectangle with zero distortion.

Hit testing exposes a limit of the API. canvas.updateElementGeometry() takes one 4x4 DOMMatrix per element, which can describe only one 2D projective plane (one homography). At the sweet spot that's enough, because all twelve 3D faces map onto the same screen-space rectangle. As soon as you orbit away, the treads and risers peel apart in screen space while Chromium's single hit box stays glued to one flat plane. The orange-cyan wireframe shows where that single hit box sits. Switching to Track pointer face raycasts the scene under your pointer and updates the single DOMMatrix to match whichever stair tread, riser or wall you're pointing at.

Live checks

These checks run on isolated fixtures and on the projection matrices without moving or focusing the gallery above.

Findings