Wooden mirror
I wanted to know if a single WebGL 2 canvas could turn a live interactive HTML form into Daniel Rozin's 1999 motorised Wooden Mirror.
Each tile averages luminance straight from texElementSubImage2D() on the GPU with zero CPU readback, tilting up to 1,764 bevelled 3D louvers toward an overhead spotlight while updateElementGeometry() keeps the controls clickable over the wood.
Tap the oversized text box on the mirror to type new letters, click Wave, Invert or +1 directly through the wood, or switch to Wave tiles to ripple your finger across the grid without popping up a keyboard. Drag Peek live HTML to reveal the aligned DOM card over the tiles.
Show the code GPU tile-state FBO, instanced 3D beveled louvers, texture upload and hit sync
- The drawable form inside the canvas. One 360×360
#source-cardsits inside<canvas content="drawable" layoutsubtree>with an oversized text input, three buttons, a contrast slider and a calibration gradient bar. - One WebGL 2 context through
ElementGL. On everypaintevent,gl.texElementSubImage2D()copies the form into a mipmapped texture; in webcam mode, frames upload from<video>only after you tap Live Webcam. - Zero-readback GPU tile luminance and servo smoothing. Pass 1 renders an
N×Nping-pongRGBA8framebuffer that box-averages 16 samples per cell, applies contrast, adds pointer ripple waves and damps each servo toward its target tilt. - Instanced 3D bevelled louvers and materials. Pass 2 draws up to 1,764 extruded 3D square tiles with
drawElementsInstanced(), clipping corners to an octagon and shading per-tile oak grain, brushed brass or recycled plastic scraps under an overhead spotlight. - Aligned hit testing via
updateElementGeometry(). Scales the 360×360 card onto the mirror square withgeometryUnit()and togglesdataset.hitTickso clicks and typing still land when the DOM overlay is at 0% opacity.
How it works
Daniel Rozin's 1999 Wooden Mirror places 830 square wooden pegs in an octagonal frame, each driven by a small servo motor tilting toward or away from an overhead gallery light. When a tile tilts upward, it catches the light and reads pale; when it tilts downward, it falls into shadow and shows its dark backing cavity.
Here the browser paints #source-card into a WebGL 2 texture through gl.texElementSubImage2D() on one ElementGL context, with mipmaps generated on each upload. I wanted to avoid reading pixels back to JavaScript on every frame because repeated readbacks from GPU canvases hurt throughput and have lost 2D contexts on Android phones. Instead, Pass 1 runs a fragment shader into a tiny N×N ping-pong RGBA8 framebuffer (42×42 is 14 KB for both buffers) that takes a 4×4 stratified average per tile, applies the contrast slider, adds up to four decaying pointer ripple waves and blends each servo smoothly toward its target angle.
Pass 2 uses gl.drawElementsInstanced() to render a 3D bevelled square tile mesh once per grid cell. Each instance fetches its angle from the state texture via texelFetch(), discards corner cells outside the octagonal aperture (leaving 840 active tiles at 30×30) and rotates around its horizontal hinge between -56° and +54°. The fragment shader computes overhead halogen lighting, cavity occlusion and procedural material detail for Oak & Pine (unique grain angle and growth rings per tile ID), Brushed Brass (anisotropic horizontal grooves and sharp metallic highlights) and Trash Plastic (curated scrap plastic colours shaded purely by physical tilt).
Because the front plane of the mirror sits at z = 0 facing a centred perspective camera, the square grid maps onto an exact axis-aligned rectangle in canvas CSS pixels. Calling canvas.updateElementGeometry(sourceCard, { canvasTransform }) with geometryUnit() keeps the invisible or peeked HTML controls locked to the tiles, while switching to Wave tiles sets pointer-events: none on the form so touch drags paint liquid waves across the wood. If WebGL 2 texElementSubImage2D() isn't available, the page draws a 5-argument drawElementImage() oak-slat fallback in 2D; if the API isn't enabled or the context is lost, it moves #source-card into plain HTML.
Live checks
These checks build their own isolated fixtures on the test stage and retire every canvas afterwards. Tap the button below to run them in this browser.
Findings
- Not verified in a live browser yet: none of the live checks or GPU shaders have been run in Chromium 157 or on Chrome 159 for Android yet. Run the checks above on a supported browser to record measured results.
- Using a tiny
N×NRGBA8ping-pong framebuffer (14 KB at 42×42) keeps luminance sampling, servo damping and pointer ripple waves on the GPU, avoiding anyreadPixels()orgetImageData()call in the render loop. - Averaging a 4×4 stratified grid per tile cell from a mipmapped
texElementSubImage2D()upload prevents thin button borders and font strokes from disappearing between sample points at 20×20 and 30×30 resolutions. - Keeping
#source-cardin an octagonal safe margin (insetting the top input and bottom contrast band by 26 px on each side while letting the middle button row span full width) stops the chamfered mirror corners from clipping any interactive HTML control.