Depth wallpaper with spatial clock occlusion
I wanted to know if one ElementGL WebGL 2 canvas can composite a live editable clock behind a foreground HTML and SVG cutout with 3-plane parallax while keeping controls clickable via updateElementGeometry(). Drag across the wallpaper, edit the date pill or toggle depth occlusion.
starting...
Show the code ElementGL two-layer slots, premultiplied depth shader, 3-plane parallax and 2D/plain fallbacks
- Two drawable layers in one canvas.
#dw-clock-layerholds the editable date pill, quick widgets and giant<output>clock, while#dw-subject-layerholds the inline SVG peak and HTML foreground badge inside one<canvas content="drawable" layoutsubtree>. - Premultiplied uploads into
ELEMENT_COUNTslots. SetsUNPACK_PREMULTIPLY_ALPHA_WEBGL = trueon creation and restore, gates uploads onhasPaintedinsidepaint, and callsstage.begin()beforestage.upload(layerEl). - Twilight sky shader and premultiplied occlusion composite. Draws the sky and distant hills at
0.35x, samples#dw-clock-layerat0.70xand#dw-subject-layerat1.35x, and blends premultiplied foreground alpha withfg.rgb + col * (1.0 - fg.a). - Parallax motion and calibrated hit geometry. Updates
updateElementGeometry()for#dw-clock-layerusinggeometryUnit()and flipsdataset.hitTickso the date input and widgets stay clickable as the clock shifts. - Five-argument 2D and plain-HTML fallbacks. Composites both layers with 5-argument
drawElementImage()without WebGL 2, or moves them into#plain-hostwhen context loss occurs.
How it works
- One
<canvas id="dw-canvas" content="drawable" layoutsubtree>owns one WebGL 2 context throughElementGL(/lib/element-gl.js). Inside it sit twodrawablesubtrees:#dw-clock-layerfor the live clock, editable date input and quick pills, and#dw-subject-layerfor the inline SVG granite ridge and engraved HTML elevation tag. - Inside the
paintlistener,hasPaintedturnstrue,stage.begin()sizes and clears the backing buffer, and only dirty slots among theELEMENT_COUNT(2) layers re-upload viastage.upload(layerEl)(gl.texElementSubImage2D()). Dragging or runningAuto driftupdates only shader uniforms andupdateElementGeometry()with zero texture re-uploads. - Setting
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true)on context creation and insideonRestoredgives premultiplied RGBA texels for both DOM layers. That stops translucent frosted pills (rgb(255 255 255 / 0.16)) from washing out to solid white and letsfg.rgb + clock.rgb * (1.0 - fg.a)blend the anti-aliased mountain edge over bright digits without dark fringes. - Each frame shifts the three visual planes at separate parallax multipliers:
0.35xfor the twilight sky and distant shader ridges,0.70xfor#dw-clock-layer, and1.35xfor#dw-subject-layer. Switching betweenDepth occlusion on,Flat overlay (clock in front)andMask alpha debugswaps compositing order in the fragment shader without changing the DOM. #dw-subject-layerstaysinertwithpointer-events: nonewhilesyncHitGeometry()positions#dw-clock-layerthroughcanvas.updateElementGeometry()scaled bygeometryUnit()and togglesdataset.hitTickso the upper widgets and date<input>stay clickable.
Live checks
Each check builds an isolated fixture on testStage() so the live wallpaper above isn't disturbed.
| Result | Experiment | Detail |
|---|
Findings
Measured in headless Google Chrome 160.0.8188.0 canary on 2026-11-27 at 412x915 and 2.625 DPR (SwiftShader WebGL). Headless Chromium 157, npm run check:jank and Chrome 159 on Android stay not verified.
- Premultiplied uploads stop frosted pill washout and edge fringes. Setting
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true)on context creation and insideonRestoredyielded true premultiplied texels (translucentrgba(255,255,255,0.20)pill measuredrgb(67,78,101)over darkrgb(15,20,36)sky instead of solid white), and blendingfg.rgb + col * (1.0 - fg.a)kept the anti-aliased ridge free of dark halos. - Separating hit-cache clears from texture uploads keeps
Auto driftat 2 uploads. Initially, flippingdataset.hitTickinsidesyncHitGeometry()triggered freshpaintevents with#dw-clock-layerinchangedElements, driving uploads from 108 to 181 in 1.2 seconds. Gatingstage.upload()on explicitslot.dirtyflags insidepaint(readingchangedElementsonly while the text input holds focus) held uploads flat at 2 during continuous parallax motion. - Don't call
stage.upload()synchronously outsidepaint. CallingdrawCurrentFrame()straight after mutating a widget button label uploaded the stale paint record and clearedslot.dirtybefore the next frame'spaintevent arrived, leaving the canvas pill one state behind. Restricting uploads to thepainthandler fixes the one-frame lag. - Three-plane parallax and clickable controls work together. Shifting sky at
0.35x, clock at0.70x(measured28.0 pxshift across-20to+20) and foreground cutout at1.35x(54.0 px) moved the peak independently across the digits whilegeometryUnit()-scaledupdateElementGeometry()kept#dw-date-tagand#dw-widget-depthclickable across a28 pxshift. - Fallbacks and reduced motion hold layout steady. Under
prefers-reduced-motion: reduce, automatic drift and sky shimmer paused and the.motion-warnnotice hid and restored#dw-stagecleanly. WithtexElementSubImage2Ddeleted, the 5-argumentdrawElementImage()2D route passed occlusion and hit-testing checks at5.61 MB; withdrawElementImagedeleted, plain HTML kept both layers legible atscrollWidth === innerWidth === 412. - Not verified on real mobile hardware: touch-dragging across the lock screen while tapping quick widgets at 412 px and 2.625 DPR on Chrome 159 for Android, real GPU frame rates, and
deviceorientationsensor tilt.