Venetian shutter-blinds 3D slat flip
I wanted to know if one ElementGL WebGL 2 canvas could slice two live drawable HTML views into pivoting 3D Venetian blind slats, keeping both front and back text unmirrored across a 90° face swap while preserving live clicks and typing at each end. Drag across the blinds, scrub the slider or press Flip blinds.
Starting canvas…
Show the code two drawable sheets, 3D ray-cast slat shader, staggered wave timing, hit-box sync and 2D fallback
- Two contrasting live HTML sheets inside one canvas. Both
#sb-scene-aand#sb-scene-bsit directly inside<canvas content="drawable" layoutsubtree>withinerttoggling between endpoints. - Perspective 3D slat ray-slab shader. Casts one ray per pixel against up to 24 oriented slat slabs, revealing dark gaps, cosine-shaded faces, metallic rim bevels and an unmirrored swap to
uTexBpast 90°. - Staggered phase wave and explicit
tMstiming. Offsets each slat's flip across the deck with deterministic timestamp stepping and immediate snapping underprefers-reduced-motion: reduce. - Hit-box calibration with
updateElementGeometry(). AppliesgeometryUnit()scaling, flipsinertandpointer-events, and togglesdataset.hitTickat 0% and 100%. - Five-argument
drawElementImage()2D fallback and plain-HTML rescue. Clips and scales individual strips across horizontal, vertical and diagonal axes without WebGL 2, or extracts both views into plain HTML on context loss.
How it works
Both #sb-scene-a and #sb-scene-b live inside one <canvas content="drawable" layoutsubtree> backed by one ElementGL WebGL 2 context from /lib/element-gl.js. I set gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true) on context creation and inside onRestored, wait for the first paint event to set hasPainted = true, and call stage.begin() before uploading changed views with stage.upload().
Rather than approximating slats with flat 2D rectangles, the fragment shader casts a perspective camera ray through each pixel and intersects up to 24 oriented 3D slat slabs aligned to the chosen Horizontal, Vertical or Diagonal axis. Each slat rotates 0° to 180° around its centre hinge with a staggered wave delay across the deck: as louvers approach 90°, cosine face shading darkens them, 5.2 px thickness rims catch a directional highlight and misses expose the dark recessed housing behind the cords.
Rotating a texture 180° around a slat hinge flips its coordinates upside down or backwards. Past 90°, the shader swaps to uTexB and negates the slat's local cross-hinge offset (sCenter - uHit) so Reverse Sheet B un-squishes upright and unmirrored from edge-on right through to 100%.
At 0% and 100% rest, syncHitGeometry() calibrates updateElementGeometry() with geometryUnit(), toggles dataset.hitTick to clear Chromium's hit-test cache, and swaps inert plus pointer-events so buttons and editable <input> fields respond only on the visible sheet. Animations pause off screen via IntersectionObserver and when document.hidden is true, while 5-argument drawElementImage() strips handle 2D-only contexts and #plain-host preserves DOM state on context loss.
Live checks
Each check builds an isolated fixture on testStage() and retires its canvas when done, leaving the demo above untouched.
| Result | Experiment | Detail |
|---|
Findings
- Measured in headless Google Chrome 160.0.8188.0 canary on 2026-11-27 (412×915 viewport, device scale factor 2.625, touch emulation, SwiftShader WebGL): all 6 live checks pass with
0errors,0lost contexts,0open snapshots and0wrong-sizedrawElementImage()draws. - At 412 px wide, the canvas holds
948×1078 px(1.02 MP,8.18 MB, peak2WebGL contexts during checks and1alive after fixture retirement), withscrollWidth === innerWidth === 412. - Staggered phase checks at 50% (
stagger = 0.55) read back[14,165,233](Sheet B) on leading slat 0,11luminance in the mid-deck louver gap, and[239,68,68](Sheet A) on trailing slat 5. Cosine shading dropped flat slat luminance from137at 180° to69while turning, and asymmetric lime/rose patterns stayed unmirrored across both horizontal and vertical axes. - Live CDP taps and typing updated counters and inputs on Front Sheet A at 0% and Reverse Sheet B at 100%, swipe drags scrubbed back from 100% to 0%,
prefers-reduced-motion: reducechecked Reduced motion and snapped flips immediately, and both the 5-argument 2D strip fallback (?route=2d) and plain-HTML fallback (withCanvasDrawElementdisabled) switched views cleanly. - Not verified:
npm run check:jank -- /shutter-blinds/(Playwright isn't installed in this environment), Chromium 157 headless, and real Chrome 159 on Android (touch scrub feel and hardware GPU frame pacing at 412 px).