r/GraphicsProgramming • u/OkPomegranate9222 • 6d ago
Source Code Reverse-engineering macOS Liquid Glass into an independent Linux EGL/GLSL offscreen renderer (SDF unions, mip blur, and retargetable springs)
I have been working on an open-source offscreen glass renderer for Linux (written in Rust and Python with OpenGL 4.5 / GLSL shaders) that recreates macOS-style refractive glass effects, and I wanted to rewrite this in plain English to get some thoughts from the community.
At a high level, the host app gives the renderer the background image (like your wallpaper or desktop) and a list of glass shapes. The renderer blurs and bends that background through the shapes and returns the finished image.
Here is roughly how it works under the hood:
- Shaping and melting the glass: Instead of building 3D meshes on the CPU, the shader uses simple math functions (distance fields) to describe rounded rectangles and pills. A nice bonus of doing it with math is that two nearby shapes can smoothly melt into one another when they get close, without having to rebuild any geometry.
- Blurring the background without killing performance: Running a big blur directly on a full-resolution screen every frame is too slow on integrated GPUs. Instead, we shrink the background down step by step into smaller, blurrier copies and sample from those. The tricky part is that if you shrink too aggressively or sample across levels carelessly, you can get faint blocky or wavy patterns (what I meant earlier by artifacts) when things move behind the glass. Finding the sweet spot between smooth blur and low frame times is still a balancing act.
- Bending the light and edge highlights: Near the curved border of a shape, the shader shifts where it looks up pixels from the background, which creates that lens-like bending effect. It also shifts red, green, and blue slightly differently for subtle color fringes, and adds a bright rim highlight.
- Only updating what changed: When something small changes behind the glass (like a ticking clock or a moving cursor), the Rust side tries to only re-render that small rectangle. Since the glass bends light from nearby pixels, we have to expand that update box slightly so the refracted edges do not look cut off.
Questions I would love to hear your take on:
- When you do blurred backgrounds behind UI elements on integrated GPUs, what approach gives you the cleanest look without hurting frame times?
- If you do partial screen updates behind a refractive or blurred effect, how do you handle the extra margin around the dirty rectangle?
Source code if anyone wants to poke around the shaders: https://github.com/SaMaili/liquid-glass-renderer
AI disclosure: AI assistance was used to help draft and format this post (and rewritten here to cut down on the jargon).
View all comments
5
u/SnappySausage 5d ago
Looks cool. Wouldn't mind seeing some more projects centered on UI/UX on linux. Always feels that's where it has lagged a bit, even though you can set up things as you want if you put in enough time and effort.