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.

Studio Focus On
04
starting...

Show the code ElementGL upload, G² superellipse SDF and bevel shader, geometry hit sync and 2D fallback
  1. Six live drawable widgets inside one canvas. Two interactive cards and four 1:1 dock icons sit directly inside <canvas content="drawable" layoutsubtree>, with user-select: text kept on the widget <input>.
  2. 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.
  3. Single ElementGL context with premultiplied uploads. Sets UNPACK_PREMULTIPLY_ALPHA_WEBGL to true on creation and restore, gates uploads on hasPainted inside paint and calls stage.begin() before stage.upload().
  4. Calibrated hit-box sync with updateElementGeometry(). Computes geometryUnit() once per resize, positions all six widget hit boxes and toggles dataset.hitTick.
  5. Five-argument 2D superellipse clip fallback. Traces a parametric superellipse Path2D and draws each tile with 5-argument drawElementImage() 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.

ResultExperimentDetail

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.