News for hackers. Stuff that matters.
Re:Liquid Glass in the Browser: Refraction with CSS and SVG by explosion-s on Monday September 08, 2025 @08:43PM (#45176046)
I made something similar to this with WebGL shaders (the benefit being it works across browsers): https://real-glass.vercel.app - The tricky thing for me was making it refract real HTML elements behind
Re:Liquid Glass in the Browser: Refraction with CSS and SVG by cycomanic on Monday September 08, 2025 @10:46PM (#45176811)
Cool this looks like it even has dispersion, i.e. colors separate at the edge of the glass element.
Re:Liquid Glass in the Browser: Refraction with CSS and SVG by lagrange77 on Tuesday September 09, 2025 @05:16AM (#45179537)
Re:Liquid Glass in the Browser: Refraction with CSS and SVG by cycomanic on Tuesday September 09, 2025 @11:21AM (#45183212)
Yes chromatic abberation is caused by dispersion.
Re:Liquid Glass in the Browser: Refraction with CSS and SVG by lagrange77 on Tuesday September 09, 2025 @12:23PM (#45184305)
Damn, outnerded.
Re:Liquid Glass in the Browser: Refraction with CSS and SVG by davidmurdoch on Monday September 08, 2025 @09:49PM (#45176474)
Impressive!
Re:Liquid Glass in the Browser: Refraction with CSS and SVG by Lorin on Tuesday September 09, 2025 @12:59AM (#45177590)
What is causing the ghosting/delay when moving the glass over text?
Re:Liquid Glass in the Browser: Refraction with CSS and SVG by kaptainscarlet on Tuesday September 09, 2025 @08:05AM (#45180779)
probably shaders are compiling and initialising on every drag movement
Re:Liquid Glass in the Browser: Refraction with CSS and SVG by IshKebab on Tuesday September 09, 2025 @02:01AM (#45177986)
Looks nice! It's too slow to actually use though. Op's is much smoother.
Re:Liquid Glass in the Browser: Refraction with CSS and SVG by qzio on Tuesday September 09, 2025 @02:52AM (#45178396)
It's the opposite on my macbook pro/chrome computer... the OP is unusable, but the webGL version is super smooth
Re:Liquid Glass in the Browser: Refraction with CSS and SVG by kaptainscarlet on Tuesday September 09, 2025 @08:05AM (#45180786)
it's extremely quick on my M3 Mac too.
Re:Liquid Glass in the Browser: Refraction with CSS and SVG by thisOtterBeGood on Tuesday September 09, 2025 @02:42AM (#45178316)
Not over here. As far as I understand Op's solution does not utilize a gpu.
Re:Liquid Glass in the Browser: Refraction with CSS and SVG by freehorse on Tuesday September 09, 2025 @03:17AM (#45178589)
I actually see gpu utilisation in OP's website when I move things (m3 pro), but this other solution shows much less gpu utilisation (prob more efficient?).
Re:Liquid Glass in the Browser: Refraction with CSS and SVG by kubeio on Tuesday September 09, 2025 @08:36AM (#45181111)
I considered WebGL, and I agree—a shader is more performant for real-time effects.

But WebGL comes with drawbacks:

- You need JS code running before anything shows up.

- Shaders can’t directly manipulate the DOM render. To make refraction work, you’d have to re-render everything into a canvas—which isn’t really “the web” anymore.

With the SVG/CSS approach, you can pre-render the displacement map (at build time or on the backend) and get the refraction visible on the very first frame. Plus, it integrates cleanly with existing, traditional UIs.

That said, this approach could definitely be improved. Ideally we’d have shader-like features in the SVG Filter spec (there was a proposal, but it seems abandoned). There are some matrix operations available in SVG Filters, but they’re limited—and for my first blog post I wanted to focus more on pedagogy, art, and technique than heavy optimization.

Re:Liquid Glass in the Browser: Refraction with CSS and SVG by kkkqkqkqkqlqlql on Tuesday September 09, 2025 @08:43AM (#45181175)
I'm on mobile and your site works much better than the WebGL one.