r/GraphicsProgramming • • 4d ago

Source Code Reverse-engineering macOS Liquid Glass into an independent Linux EGL/GLSL offscreen renderer (SDF unions, mip blur, and retargetable springs)

Post image

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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).

3 Upvotes

3 comments sorted by

•

u/AutoModerator 4d ago

Recently updated rules. Please check that your post is in compliance with Rules 1, 4, 5, and 6 on the sidebar. TL;DR:

  • No showcases.

  • Disclose AI usage in post or project.

  • Present a topic to talk about, e.g. how something works.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

4

u/SnappySausage 4d 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.

2

u/CodyDuncan1260 3d ago

 For multi-level backdrop blur behind refractive UI elements, how do you balance mip-pyramid artifacts/ringing against frame-time budgets on mobile/integrated GPUs (e.g. Mesa Intel / llvmpipe)?

Definine "ringing"? And why are artifacts and frame times in contention?

 AI disclosure: AI assistance was used to help draft and format this Reddit post.

AI can be useful for helping with drafts, but certain models, especially Claude Opus, are optimized for information density. That's not strictly a bad thing, but it makes reading extremely difficult. 

If I'm going into reading a published paper, I'm going to expect a ton of information density, especially in jargon terms. I am prepared to parse that slowly, read through references, build up notes, just to understand the first few opening paragraphs.

Certain models made for task solving are trained on such papers and technical documents. Let's them go further with fewer tokens, which users see as a win. But, it writes like this, and makes it really quite heavy to parse. 

Finally, it doesn't help when a model decides to use an odd synonym. I saw one post talking about performance use "price" when they meant "measure" in terms of comparing benchmark results. "ringing" makes me wonder if it's the same type of artifact.

My request to OP: rewrite for humans who aren't planning to spend the next hour brushing up their 2D shape rendering terms. I'm certain this is fine for the parts of us that handle that day to day, but for the rest of us it'd be a kindness to express the idea more simply and expansively. Write as you understand it, not the AI assistant, and I'm certain I and more of the rest of us could understand it better.