--- name: refract-rain-glass description: Build liquid glass buttons and panels over a moving scene with wet edges, chromatic refraction, press response and legible HTML labels. Use when the glass must distort real background detail. --- # Refract Rain Glass ![A live scene bends through a beveled edge under a moving film of water.](assets/preview.jpg) Use a clean copy of the live scene as the optical source. Keep labels, keyboard focus and hit areas in the DOM above the optical pass. ## Assemble the material - Render the scene to a texture. Read it from a separate full-screen pass. Never sample a framebuffer while writing to it. Include any atmospheric streaks that should bend behind the lens. - Include [lens.glsl](assets/lens.glsl). Its uniforms use CSS pixels, bottom-left origin, center XY and half-size ZW. Set glassViewport to the CSS surface size. Fill glassRects with the four capsules. Zero unused slots. A positive pickerRect width enables the optional eight-tile panel. Use pickerReveal = 1 for a settled panel. - Update glassContact with local 0–1 UV, one-based control index and press weight. Invert pointer Y. Reset on leave, cancel or lost capture. Re-measure on font load, resize and during transforms. Have the lens respond to a press while the label stays sharp. - Sample the returned UV for the green channel. Offset red and blue slightly in opposite directions along the distortion. Suppress separation on the flat face. The helper bends a virtual lip with IOR 1.46 and computes an opposed pair of narrow highlight strips. Avoid adding a heavy continuous CSS border. ```glsl float face, rim; vec2 reflection, light; vec2 q = glassRay(uv, vec4(0.), 0., face, rim, reflection, light); vec2 d = (q - uv) * .045; vec3 rgb = vec3(texture2D(sceneTex, clamp(q+d,0.,1.)).r, texture2D(sceneTex,q).g, texture2D(sceneTex,clamp(q-d,0.,1.)).b); rgb = mix(rgb, texture2D(sceneTex,reflection).rgb, rim); ``` Apply scene tone mapping once. Darken the return band with light.y and lift the key with light.x. Add [water.glsl](assets/water.glsl) with `uniform float clock;` and `uniform vec4 seasonMix;`. Call `glassShower(uv * glassViewport, rgb)` in display space. Use original screen coordinates here so a moving highlight cannot pull a drop off the rim. Ease seasonMix.x from zero to one for rain. ## Check Move a striped image behind the control. The stripe should bend near the lip, stay recognizable through the center and leave the label sharp. Compare dry and wet frames at 1× and 2×. Tab through controls, then disable WebGL and retain keyboard access with a translucent CSS fill.