Spatial visionOS glass window
I wanted to know if one ElementGL WebGL 2 canvas could render a 3D tilted spatial glass window with mipmapped Gaussian frost, Snell rim refraction, chromatic edge dispersion, directional bevel speculars and gaze button glow while keeping tilted HTML controls clickable with updateElementGeometry().
Move your pointer (or drag on touch) across the stage to steer the 3D window tilt, specular rim highlight and radial button glow. Toggle Dim glass, switch tracks or edit the spatial note directly inside the tilted panel.
Show the code Mipmapped room and Gaussian blur FBOs, Snell dispersion bevel shader, 3D homography and hit geometry
- The live
drawablespatial workspace panel. One<section id="vg-panel" drawable>holds translucent pill buttons, room chips, a range slider and an editable note input inside<canvas content="drawable" layoutsubtree>. - 3D perspective projection and exact planar ray-plane unprojection. Builds matching
uMvpand 3DDOMMatrixtransforms plus the 3x3 inverse homographyinvHomographyso pointer hover maps back into tilted panel coordinates. - Procedural room, Gaussian frost, Snell rim dispersion and bevel specular shader. Samples mipmapped room and blur FBOs through a rounded-box SDF with R/G/B bevel dispersion, pointer-tracked rim highlights and button proximity glow before compositing premultiplied DOM UI.
- Offscreen FBO pipeline with explicit FBO/VAO unbind. Renders the architectural room into
roomFbowith mipmaps, blurs through two separable Gaussian passes intoblurFboB, and unbinds both FBO and VAO before screen compositing. - Single
ElementGLstage, premultiplied upload and projective hit boxes. EnablesUNPACK_PREMULTIPLY_ALPHA_WEBGLon creation and restore, callsstage.begin()beforestage.upload(), and updatesupdateElementGeometry()withgeometryUnit(). - Five-argument
drawElementImage()2D fallback and plain HTML rescue. Draws a 2D rounded frosted slab and directional bevel when WebGL 2 is absent, or unwraps#vg-panelinto#plain-hoston context loss.
How it works
- Each frame on the WebGL 2 path runs in two stages inside the one
ElementGLcontext. First,GlassPipelinerenders the proceduralStudio DawnorPassthrough Loftroom into an offscreenroomFbowithgenerateMipmap(), runs four separable 13-tap Gaussian blur passes across two half-resolution FBOs, and finishes by callinggl.bindFramebuffer(gl.FRAMEBUFFER, null)andgl.bindVertexArray(null). - Next,
stage.begin()sets up the screen framebuffer, uploads#vg-panelonly whendomDirtyis set insidepaint(withUNPACK_PREMULTIPLY_ALPHA_WEBGL = true), draws Pass 0 for the full-screen room and 3D perspective drop shadow, and draws Pass 1 with the 3D tilted panel matrixuMvp. - Inside Pass 1,
sdRoundBox()masks the rounded window perimeter and calculates the curved edge normal. Snell's law bends screen UVs separately for red, green and blue around the bevel rim while sampling mipmapped room and Gaussian blur textures behind the frosted core. - A sharp 1 to 2 px specular rim glides around the perimeter toward
uLight, paired with an opposite secondary catchlight and subtle chromatic bevel tint. Before compositing the crisp premultiplied DOM texture on top, the shader illuminates the six[data-gaze-slot]pill bounds with a radial highlight centred at the ray-unprojected pointer positionuGazeLocal. syncHitGeometry()passes the matching 3D perspectiveDOMMatrixscaled bygeometryUnit()tocanvas.updateElementGeometry()and togglesdataset.hitTickso every pill button, range scrubber and text input remains clickable while tilted.
Live checks
Each check builds an isolated fixture on testStage() and retires its canvas afterwards so the live window above stays untouched.
| Result | Experiment | Detail |
|---|
Findings
Measured in headless Google Chrome 160.0.0.0 canary on 2026-11-27 at 412x915 and 2.625 DPR (SwiftShader WebGL). Chrome 157, npm run check:jank and Chrome 159 on Android stay not verified.
- Works: mipmapped room and Gaussian blur FBOs inside one
ElementGLcontext. Separating the room backdrop and four 13-tap Gaussian blur passes into half-res FBOs and unbinding both FBO and VAO beforestage.begin()rendered atglErr=0across0.98 MP(7.85 MB) with0lost contexts,0open snapshots and0unasked readbacks. - Works: premultiplied translucent glass DOM and pointer-tracked bevels. Keeping
UNPACK_PREMULTIPLY_ALPHA_WEBGL = trueat context creation, inonRestoredand in every fixture lets translucent pills blend cleanly over frosted glass. MovinguLightfrom top-left to bottom-right shifted 1 to 2 px rounded bevel luminance from255.0vs91.3to145.5vs255.0, tilting14°/22°shifted corner luminance by48.5, and gaze proximity brightened the centred button slot by+131.0. - Works: projective
updateElementGeometry()under 3D tilt. Scaling the 3D perspectiveDOMMatrixbygeometryUnit()and togglingdataset.hitTickkept both an off-centre fixture button at16°/-24°(3.4 pxshift) and the live tilted#vg-nextbutton clickable viaelementsFromPoint(). - Works: fallbacks and reduced motion notice. Deleting
texElementSubImage2D()fell back cleanly to 5-argumentdrawElementImage()(0wrong-draw-size hits), deletingdrawElementImage()unwrapped#vg-panelinto#plain-hostwithscrollWidth === innerWidth === 412, and togglingprefers-reduced-motion: reduceshowed.motion-warnwith workingHide stageandShow stagecontrols. - Not verified yet: real Android Chrome 159 touch interaction and GPU frame rates at 412 px and 2.625 DPR, plus
npm run check:jank.