Show HN: CSS generator for a high-def glass effect (opens in a new tab)glass3d.dev
420 pointsCross-browser compatibility is actually the reason I rely on ::before and ::after pseudo-elements to build up the effect. Move the color/opacity to the main element, and you’ll get weird color bleed on the corners in Chrome. Move the texture, and it muddles the bevel’s specular highlight. Move the bevel, and it gets blurred out by the backdrop-filter. And so on!
Layers include:
* Adjustable blur, brightness, and saturation (backdrop-filter)
* Subtle translucent texture
* Faux 3D bevel (using box-shadows, not an outline)
Glassmorphism is rather heavy on resources, so it’s best used as an accent and avoided on wide desktop elements.
Should be compatible with recent versions of Chrome, Safari, and Firefox (desktop and mobile). If you spot bugs or rendering glitches, I’d love to know!
Side note: this is an early preview of a framework-agnostic glass SCSS/component library I’m building.
Comments (117) 32 threads
Show all comments
Showing thread 1 of 32
I instead assume that materials are by default more similar to paper.
Note the circle before it intersects with the rect, without accounting for pixels beyond the bounds, the blur is incorrect because the kernel doesn’t take into effect the circle.
Note the blur after extending the kernel beyond the visible bounds. While the blur is correct, the albedo of the shape passing through the rect no longer makes sense. The circle is not emissive, and yet despite this, you see the blur of the circle behind the rectangle without it intersecting in a full-bright environment. Why can we assume the environment is full-bright? Because there is no lighting. Only albedo.
Neither are correct.
It's too exaggerated for, say, a kernel of 32px.
It’s not impossible that this will be adjusted in the future in some way, like how browsers quite some years ago shifted to premultiplying colours so that a gradient from white to transparent doesn’t go through semitransparent grey, but browsers are acting according to spec.
For me the tweaked version is much more distracting and looks more wrong due to conflicting depth signals.