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
- One live
drawableposter inside the canvas. The headline input, colour swatches, toggle buttons and range slider are ordinary HTML inside one<canvas content="drawable" layoutsubtree>. - One WebGL 2 context through
ElementGL. On everypaintevent, the poster uploads viagl.texElementSubImage2D()into a mipmapped anisotropic texture so text stays sharp when stretched across horizontal treads. - Projective texturing across every stair tread, riser and wall. Each fragment transforms its 3D world position by the fixed projector matrix
uProjVPto find its poster UV. When the viewer camera matches the projector, depth cancels out and every face snaps into one flat rectangle. - Exact 4x4 homography for
updateElementGeometry(). Intersecting the projector ray for element pixel(ex, ey)with any 3D planeN . X = dis linear in homogeneous coordinates, so oneDOMMatrixmatches any single face (and all twelve faces at once at the sweet spot). - 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
- One live HTML element uploaded with
texElementSubImage2D()can be projectively textured across arbitrary 3D architecture in a single WebGL 2 pass on oneElementGLcontext, with mipmaps and anisotropic filtering keeping text legible on grazing stair treads. - At the projector's sweet spot, depth cancels out algebraically across all twelve non-coplanar faces, so one
DOMMatrixpassed toupdateElementGeometry()aligns every button, input and range slider across the stairs and walls. - Off-axis (for example at 35° orbit), a single
updateElementGeometry()matrix diverges by tens of CSS pixels across the five steps because one 4x4 matrix can only represent a single plane. - Intersecting projector rays with a face's plane
N . X = dyields an exact homogeneous 4x4 matrix per face. Raycasting the stairs on pointer move and swapping that matrix keeps off-axis clicks accurate on whichever step or wall is under the pointer, though keyboard focus rings and browser selection rects still see only the active plane.