3D opening title crawl
I wanted to know if one ElementGL WebGL 2 canvas could project a live editable HTML article onto a receding 3D cinema crawl over a starfield, fade far lines cleanly into space, and keep tilted buttons and inputs clickable with updateElementGeometry().
Edit the yellow episode heading or transmission text directly on the receding plane, or switch to Flat 0° (Edit) and scrub Progress to inspect any act head-on. Click Jump to Act II or Pause crawl inside the crawl to drive playback from the tilted DOM.
Show the code ElementGL mipmapped upload, 3D perspective crawl shader, projective DOMMatrix and 2D trapezoid fallback
- The live
drawablecrawl article. One<article drawable>holds cinema-yellow semantic HTML, an editable<input>, a<textarea>and interactive buttons inside<canvas content="drawable" layoutsubtree>. - One
ElementGLcontext with premultiplied uploads and mipmaps. SetsUNPACK_PREMULTIPLY_ALPHA_WEBGLtotrue, callsstage.begin()beforestage.upload()insidepaint, and builds trilinear anisotropic mipmaps aftertexElementSubImage2D(). - Deep space starfield and anti-shimmer horizon fade shader. Pass 0 draws layered stars and nebula haze; Pass 1 samples the mipmapped DOM texture with distance LOD softening and a smooth screen-space fade near the top horizon.
- True 3D camera, tilt and scroll travel matrix. Builds the 4x4
uMvpmatrix mapping unit DOM UVs onto the tilted receding plane across 0° to 68° and 0% to 100% progress. - Calibrated projective
updateElementGeometry(). Maps element CSS pixels through the same perspective matrix, scales bygeometryUnit()and togglesdataset.hitTickso tilted buttons and fields stay clickable. - Five-argument
drawElementImage()trapezoid 2D fallback. When WebGL 2 is absent, draws horizontal clipped strips scaled by perspective depth over a 2D starfield.
How it works
- One
ElementGLcontext draws two passes on each frame. Pass 0 renders a procedural starfield and subtle nebula haze on a full-canvas quad. Pass 1 draws#crawl-articleusing a 4x4 perspective matrixuMvpcomputed from the tilt angle (0°to68°) and scroll progress (0%to100%). #crawl-articleonly uploads onpaintevents when its DOM content changes (initial load, typing in the heading or textarea, or clicking a button that updates the badge). While scrolling at 60 fps, each frame only updates uniforms and the 4x4 matrix with zero texture re-uploads.- Because Chromium's
texElementSubImage2D()uploads straight-alpha RGBA whenUNPACK_PREMULTIPLY_ALPHA_WEBGLis left atfalse, the script setsgl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true)on context creation and restore so anti-aliased yellow text on a transparent article background blends over dark space without grey fringing. - Right after
stage.upload(articleEl), the page enablesLINEAR_MIPMAP_LINEAR, up to 8xEXT_texture_filter_anisotropic, and callsgl.generateMipmap(gl.TEXTURE_2D)so shrinking lines near the top vanishing horizon stay smooth instead of shimmering. syncHitGeometry()sends the matching 4x4 projectiveDOMMatrix(scaled bygeometryUnit()) tocanvas.updateElementGeometry()and flipsdataset.hitTickwhenever the plane moves or before pointer presses.
Live checks
Each check builds an isolated fixture on testStage() so the live crawl above isn't disturbed.
| 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 157, Playwright check:jank and Chrome 159 on Android stay not verified.
- Works: mipmapped
texElementSubImage2D()without per-frame uploads. EnablingLINEAR_MIPMAP_LINEARandEXT_texture_filter_anisotropicon the texture returned byElementGL.upload()withUNPACK_PREMULTIPLY_ALPHA_WEBGL = truerenders anti-aliased yellow text smoothly into the deep space horizon, and mipmaps only rebuild when edits firepaint. - Works: keeping all points in front of the near plane. Choosing a
4.9-unit camera distance and adaptingsTopsmoothly between flat0°and tilted55°keeps homogeneousw > 1.4across the entire tall article at every slider extreme, preventing behind-camera clipping in both GLSL andDOMMatrix. - Works: projective
updateElementGeometry()on tilted controls. Scaling thendcToCss * VP * uvToWorld * pxToUvmatrix bygeometryUnit()alignselementsFromPoint()with buttons inside the crawl at both0°flat and50°–55°tilted planes. - Limit in the 2D fallback: drawing 26 clipped horizontal strips with 5-argument
drawElementImage()creates a receding trapezoid silhouette without WebGL 2, but affine strip scaling leaves visible slice seams across large display headings and borders because 2D canvas can't interpolate1/winside a strip. - Not verified on real mobile hardware: touch-tapping tilted buttons while crawling at 412 px and 2.625 DPR on Chrome 159 for Android, on-screen keyboard opening inside a tilted
<textarea>, and real GPU frame rates.