Continuous-curvature G² squircle mask and glass bevel vs CSS border-radius
I wanted to see how a continuous-curvature G² superellipse looks on live DOM widgets compared to CSS border-radius. Drag the split curtain across the cards, sweep exponent n from 2 to 12, move your pointer to shift the glass bevel glint and turn on curvature highlights to spot the flat-to-arc kink.
Show the code ElementGL upload, G² superellipse SDF and bevel shader, geometry hit sync and 2D fallback
- Six live drawable widgets inside one canvas. Two interactive cards and four 1:1 dock icons sit directly inside
<canvas content="drawable" layoutsubtree>, withuser-select: textkept on the widget<input>. - Exact superellipse SDF, analytical curvature and glass bevel shader. Evaluates
|x/a|^n + |y/b|^n = 1, normalises distance by its analytical gradient for pixel-accurate bevels and plots the CSS flat-to-arc kink across the split curtain. - Single ElementGL context with premultiplied uploads. Sets
UNPACK_PREMULTIPLY_ALPHA_WEBGLtotrueon creation and restore, gates uploads onhasPaintedinsidepaintand callsstage.begin()beforestage.upload(). - Calibrated hit-box sync with
updateElementGeometry(). ComputesgeometryUnit()once per resize, positions all six widget hit boxes and togglesdataset.hitTick. - Five-argument 2D superellipse clip fallback. Traces a parametric superellipse
Path2Dand draws each tile with 5-argumentdrawElementImage()when WebGL 2 isn't present.
How it works
CSS border-radius joins straight sides (curvature κ = 0) directly to circular corner arcs (κ = 1/R). That abrupt step leaves a visible reflection kink along bevels and chrome edges even though the tangent itself stays smooth. A Lamé superellipse, |x/a|^n + |y/b|^n = 1 with exponent n > 2 (typically n = 4.8), sends its curvature smoothly to zero as it meets the midpoints, giving continuous G² curvature around every edge.
Here all six live HTML widgets sit inside one <canvas content="drawable" layoutsubtree> backed by a single ElementGL WebGL 2 context from /lib/element-gl.js. Inside the paint handler, stage.begin() sizes the drawing buffer before stage.upload() uploads only dirty widgets through gl.texElementSubImage2D() with UNPACK_PREMULTIPLY_ALPHA_WEBGL set to true.
In the fragment shader, each widget quad expands by an 8 px bleed margin so drop shadows and curvature halos aren't clipped at edge midpoints. The shader divides the superellipse implicit field by its gradient norm to recover pixel-scale signed distance and outward 2D normals, clips the live DOM texture cleanly inside the curve, adds subtle edge refraction plus an angled inner glass bevel driven by the pointer, and optionally compares against an equivalent CSS border-radius arc matched at the 45° corner diagonal.
Because shader masking doesn't move Chromium's hit boxes, syncTileGeometries() scales each widget's position by geometryUnit() and flips dataset.hitTick so focus buttons, colour swatches, the live counter and the editable label stay clickable. An IntersectionObserver and document.hidden pause ambient drift off screen, while reduced motion stops light animation and jumps presets cleanly.
Live checks
Each check creates an isolated fixture on testStage() and retires its canvas afterwards so the visible dock 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. Real Chrome 159 on Android and Playwright check:jank stay not verified.
- Works: gradient-normalised superellipse SDF keeps bevel widths uniform. Dividing
(|x/a|^n + |y/b|^n)^(1/n) - 1by its analytical gradient norm produces exact CSS-pixel edge distance on both1:1dock icons and rectangular cards, so the inner glass bevel stays crisp acrossn = 2to12. - Works: matching CSS
border-radiusat the 45° diagonal isolates the shoulder kink. PickingR = min(a,b) * (1 - 0.5^(1/n)) / (1 - 1/sqrt(2))aligns both curves at the corner diagonal while exposing the exact shoulder divergence and the0 -> 1/Rcurvature jump on the CSS side. - Works: 8 px quad padding prevents midpoint halo clipping. Expanding each
ElementGLquad by 8 CSS px while samplinguTexinside the unpadded DOM box keeps curvature difference halos and outer bevel rings visible along flat midpoints. - Not verified on mobile hardware: touch-dragging bevel light angles and typing into the clipped
<input>on Chrome 159 for Android at 412 px and 2.625 DPR, plus fullnpm run check:jankprofiling.