tvOS multi-layer parallax poster
I wanted to know if one ElementGL WebGL 2 canvas could tilt three separate drawable HTML layers as a tvOS poster card, cast soft parallax shadows between them, sweep a glossy squircle sheen across the face and keep tilted controls clickable with updateElementGeometry().
Hover or drag across the poster to pivot the three layers and sweep the diagonal gloss sheen. Edit the film title directly on the foreground plane, tap Play trailer or + Watchlist while tilted, and adjust Split layers from 0 px flush to 40 px exploded depth.
Show the code 3-layer markup, 3D uMvp projection, inter-layer shadow shader, ElementGL uploads and 2D fallback
- Three independent
drawableposter layers. Background artwork (depth 0), midground emblem and pills (depth 1), and foreground editable title and action buttons (depth 2) live inside one<canvas content="drawable" layoutsubtree>. - Per-layer 3D perspective
uMvpand hit-test matrix. Maps each layer atz = k * splitWorldthrough shared yaw/pitch rotation and camera projection, returning both clip-spaceuMvpand projectiveDOMMatrix. - Squircle mask, inter-layer shadows and diagonal specular sheen. Clips corners to a continuous squircle SDF, samples blurred upper-layer alpha opposite the pointer light, and sweeps a glossy specular highlight across the card.
- Single
ElementGLcontext, premultiplied uploads and geometry sync. SetsUNPACK_PREMULTIPLY_ALPHA_WEBGL = true, gates uploads onhasPaintedinsidepaint, callsstage.begin()beforestage.upload(), and updatesupdateElementGeometry()scaled bygeometryUnit(). - Five-argument
drawElementImage()2D fallback and plain-HTML rescue. Renders affine parallax layers with 2D cast shadows when WebGL 2 is absent, and moves the three layers into#plain-hoston context loss.
How it works
- Each poster layer lives in its own
268 × 376CSS pixeldrawablecontainer inside#tv-canvas. Only#poster-title-inputand the two action buttons on#tv-layer-fgaccept pointer events;#tv-layer-bgand#tv-layer-midstay non-interactive so background layers never intercept taps aimed at the floating controls. ElementGLowns the page's single WebGL 2 context. Inside thepainthandler, I callstage.begin()first and then upload only whichever layers changed viastage.upload(layer)withUNPACK_PREMULTIPLY_ALPHA_WEBGLset totrue. Pointer drags and auto-tilt animate at 60 fps by updating matrices and uniforms without re-uploading DOM textures.- To cast real parallax drop shadows, Pass 1 (
#tv-layer-bg) binds#tv-layer-midon texture unit 1 and#tv-layer-fgon texture unit 2, blurring their alpha masks at UV offsets opposite the pointer light. Pass 2 (#tv-layer-mid) binds#tv-layer-fgon unit 1 so the title and buttons cast a sharper shadow onto the midground emblem strip. syncHitGeometry()passes each layer's 3D projectiveDOMMatrixscaled bygeometryUnit()tocanvas.updateElementGeometry()and flipsdataset.hitTickwhenever the transform changes so Chromium's hit-test cache stays aligned with the tilted card.
Live checks
Each check builds its own isolated fixture on testStage() and retires its canvas when finished, leaving the poster above untouched.
| Result | Experiment | Detail |
|---|
Findings
Measured in headless Google Chrome 160.0.8188.0 canary on 2026-11-27 at 412 px and 2.625 DPR (SwiftShader WebGL). Chrome 159 on Android and npm run check:jank stay not verified.
- Works: multi-layer
texElementSubImage2D()with inter-layer cast shadows. Binding the midground texture on texture unit 1 and foreground texture on texture unit 2 lets the shader blur upper alpha masks at UV offsets opposite the pointer light in oneElementGLcontext (1.09 MP,8.68 MB,0GL errors). - Works: Z-separation drives real parallax travel. Tilting rightward with
Split layersraised from0 pxto36 pxshifts the foreground marker relative to the background centre from-0.1 pxto+21.0 px, while pointer tilt from(-1, -1)to(+1, +1)sweeps corner specular luminance from111/23to23/112. - Works: tilted controls stay clickable and editable. Scaling each layer's projective
DOMMatrixbygeometryUnit()and togglingdataset.hitTickkeepsPlay trailer,+ Watchlistand#poster-title-inputresponsive to real pointer clicks at tilted angles. - Not verified on mobile hardware: touch dragging, glossy frame rate, and soft keyboard behaviour on
#poster-title-inputin Chrome 159 for Android at 412 px and 2.625 DPR.