dinggao.
WEBGL2 OPTICAL SHADER GUIDE · ZERO DEPENDENCIES

Apple Liquid Glass in WebGL2: Zero-Dependency 60fps HTML Code

CSS backdrop-filter applies a flat Gaussian blur that feels like frosted plastic. Real optical glass needs analytical SDF edge refraction, 1.12 / 1.00 / 0.88 RGB chromatic dispersion, and dual-direction Fresnel rim highlights. Try 7 free MIT single-file WebGL2 components live below, inspect the shader math, and paste straight into Grok Build (ex-Cursor), Gemini, or Claude Code.

FREE & MIT OPEN SOURCE

7 Free Single-File WebGL2 Liquid Glass Components

View all 126 finals
液态玻璃悬浮 Dock
Play & Copy HTML

WebGL2 Liquid Glass Floating Dock

Real-time WebGL2 convex SDF refraction shader with smooth optical lensing across floating monochrome dock icons.

Free
液态玻璃分段胶囊
Play & Copy HTML

WebGL2 Liquid Glass Segmented Capsule

WebGL2 segmented control with crisp RGB chromatic dispersion (1.12/1.00/0.88) and liquid lensing across tabs.

Free
液态玻璃轨道放大镜
Play & Copy HTML

WebGL2 Liquid Glass Orbital Magnifier

Draggable WebGL2 spherical glass magnifier lens with physically-inspired edge refraction over crisp typography.

Free
灵动岛液态融合
Play & Copy HTML

WebGL2 Dynamic Island Liquid Morph

WebGL2 smooth-min metaball Dynamic Island layered with Canvas 2D live equalizer UI and detached satellite ring.

Free
双液滴光学透镜
Play & Copy HTML

WebGL2 Dual-Droplet Optical SDF Lens

Two optical glass droplets fusing via smooth-min SDF over crisp typography with real-time lensing and sky-blue aura.

Free
液态玻璃流体开关
Play & Copy HTML

WebGL2 Liquid Glass Fluid Toggle

Velocity-stretched liquid glass toggle switch with smooth optical highlights and crisp tactile state morph.

Free
液态玻璃形变操作胶囊
Play & Copy HTML

WebGL2 Liquid Glass Morphing Action Pill

WebGL2 liquid-glass morphing action pill with smooth SDF metaball fusion and keynote spring overshoot.

Free

OPTICAL COMPARISON

Why CSS backdrop-filter Falls Short of Real Liquid Glass

Optical PropertyCSS backdrop-filterDinggao WebGL2 SDF
Edge optical refractionNone — uniform flat blurAnalytical SDF normal bending (pow(edgeT, 2.05))
Core lens magnificationNot possible with CSS blurSubtle radial lens magnification over crisp 2× texture
RGB chromatic dispersionRequires heavy SVG filter hacksNative 3-channel UV split (1.12 / 1.00 / 0.88)
Specular Fresnel rimStatic 1px borderDual-direction Fresnel key + cold-sky bounce light
Runtime bundle & FPSCan lag on mobile compositors0 KB dependencies · single fullscreen pass · 60fps

PRODUCTION SHADER ARCHITECTURE

3 Engineering Details Behind Every 60fps Liquid Glass File

STEP 01

Aspect-Locked Scale (Zero Portrait Distortion)

Never scale glass width by viewport width and height by viewport height independently. Derive a single uniform fitW and clamp corner radius r = min(halfSize.x, halfSize.y) in GLSL so desktop ultrawides and 390px mobile viewports stay optically proportional.

function getLayout(w, h) {
  const safeW = Math.max(2, w);
  const safeH = Math.max(2, h);
  const aspect = safeW / safeH;
  const portraitBoost = aspect < 1 ? clamp(1.0 + (1.0 - aspect) * 0.55, 1.0, 1.28) : 1.0;
  const fitW = Math.min(safeW * portraitBoost, safeH * 1.6);
  const sc = fitW / 640;
  return { fitW, sc, cx: safeW * 0.5, cy: safeH * 0.52 };
}
STEP 02

Analytical Capsule SDF + Convex Bezel Refraction

Instead of heavy 3D raymarching, compute an analytical rounded-box SDF and its exact normal gradient. Using pow(edgeT, 2.05) keeps the interior readable while bending pixels sharply across the curved outer 74% bevel.

// Analytical rounded-capsule SDF + convex bezel refraction (#version 300 es)
float r = min(u_halfSize.x, u_halfSize.y);
float halfLen = max(0.0, u_halfSize.x - r);
float d = sdRoundedBox(p, u_halfSize, r);

vec2 grad = gradCapsule(p, halfLen);
float bezelW = r * 0.74;
float edgeT = clamp(1.0 + d / bezelW, 0.0, 1.0);

float rimProfile = pow(edgeT, 2.05);
vec2 rimRefract = -grad * rimProfile * (25.5 * u_scale) / u_res;
vec2 coreMag = -p * 0.115 / u_res;
vec2 baseDisp = rimRefract + coreMag;
STEP 03

Restrained 1.12 / 1.00 / 0.88 RGB Dispersion + Dual Fresnel

Heavy rainbow aberration looks like cheap neon. Splitting Red, Green, and Blue UV offsets by 1.12 / 1.00 / 0.88 alongside an opposing white key light and cold-sky (#38BDF8) bounce delivers studio-grade glass without color noise.

// Subtle RGB chromatic dispersion (1.12 / 1.00 / 0.88) + dual Fresnel rim highlights
vec2 uvR = clamp(v_uv + baseDisp * 1.12, 0.001, 0.999);
vec2 uvG = clamp(v_uv + baseDisp * 1.00, 0.001, 0.999);
vec2 uvB = clamp(v_uv + baseDisp * 0.88, 0.001, 0.999);

vec3 refracted = vec3(sampleScene(uvR).r, sampleScene(uvG).g, sampleScene(uvB).b);

float rimBand = pow(edgeT, 3.3);
vec2 dirA = normalize(vec2(-0.62, 0.78));
vec2 dirB = normalize(vec2( 0.62, -0.78));
float fresnelA = pow(max(0.0, dot(grad, dirA)), 1.5) * rimBand;
float fresnelB = pow(max(0.0, dot(grad, dirB)), 1.9) * rimBand;

vec3 glass = mix(refracted, vec3(0.99, 0.995, 1.0), clamp(fresnelA * 0.95, 0.0, 1.0));
glass += vec3(0.220, 0.741, 0.973) * fresnelB * 0.56;

PRO OPTICAL SERIES · 114 PRO FINALS IN LIBRARY

More Pro Liquid Glass & Optical Controls (Playable Live)

液态玻璃精密滑块

WebGL2 Liquid Glass Precision Slider

WebGL2 · Liquid Glass

Unlock Pro
液态玻璃环形光学透镜

WebGL2 Liquid Glass Annular Ring

WebGL2 · Torus SDF

Unlock Pro
长虹压纹玻璃折射幕

WebGL2 Fluted Reeded Optical Glass

WebGL2 · Fluted Glass

Unlock Pro
液态玻璃弹簧数字翻牌器

WebGL2 Liquid Glass Spring Counter

WebGL2 · Liquid Glass

Unlock Pro
菲涅尔同心圆透镜折射

Fresnel Lens Distortion

Fresnel · WebGL2

Unlock Pro
雨滴水波磨砂玻璃幕

Raindrop Frosted Glass

Water Drops · Glass

Unlock Pro

FAQ

WebGL2 Liquid Glass — Common Questions

Does WebGL2 Liquid Glass work smoothly on mobile Safari and iOS?

Yes. Every Dinggao Liquid Glass component caps devicePixelRatio at 2, locks geometry to an aspect-safe uniform scale (preventing portrait capsule distortion), and renders a single fullscreen triangle pass with pre-baked 2D Canvas textures so iOS Safari and modern Android browsers stay locked at 60fps.

How heavy is this compared to Three.js or React Three Fiber?

Zero external dependencies. Each component is a single self-contained HTML file (~12–22 KB uncompressed) using raw WebGL2 (#version 300 es) and Vanilla JS—no 600 KB 3D engine, no bundler lock-in, and trivial for Grok Build (formerly Cursor), Gemini, or Claude Code to port into React, Vue, or Next.js.

Can I use the 7 free Liquid Glass components in commercial projects?

Yes. All 12 free finals on Dinggao (including the 7 Liquid Glass pieces on this page) are open-sourced under the MIT license on GitHub and free for personal and commercial products. The remaining Pro pieces unlock with a single Founding Lifetime pass ($49 one-time) or subscription.