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.

Front sheet · A 01 · Daylight · Ivory

Editorial front sheet

Each horizontal, vertical or diagonal strip pivots 0° to 180° around its centre hinge while staying live at 0%.

0 saved
Reverse sheet · B 02 · Night · Cobalt

Inverted reverse sheet

Past 90° the shader maps the back face unmirrored so text reads straight upright as the wave settles at 100%.

0 pulses

Starting canvas…

Show the code two drawable sheets, 3D ray-cast slat shader, staggered wave timing, hit-box sync and 2D fallback
  1. Two contrasting live HTML sheets inside one canvas. Both #sb-scene-a and #sb-scene-b sit directly inside <canvas content="drawable" layoutsubtree> with inert toggling between endpoints.
  2. 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 uTexB past 90°.
  3. Staggered phase wave and explicit tMs timing. Offsets each slat's flip across the deck with deterministic timestamp stepping and immediate snapping under prefers-reduced-motion: reduce.
  4. Hit-box calibration with updateElementGeometry(). Applies geometryUnit() scaling, flips inert and pointer-events, and toggles dataset.hitTick at 0% and 100%.
  5. 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.

ResultExperimentDetail

Findings