Skip to content

kaixin-l/LiquidGlass

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LiquidGlass logo

Real‑time frosted glass and liquid‑like refraction for any SwiftUI view – no screenshots, no boilerplate.


✨ Features

🔍 Zero screenshots Background is captured automatically – just drop liquidGlassBackground on any view.
Real‑time Optimised MTLTexture snapshots + lazy redraw; redraws only when the background actually changes.
🛠 Flexible update modes .continuous, .once, .manual via the updateMode modifier.
🧩 Pure SwiftUI Works seamlessly in both worlds.
💤 Battery‑friendly MTKView stays paused until the provider notifies it – no wasted frames.

🛠 Installation

Add LiquidGlass through Swift Package Manager:

https://github.com/BarredEwe/LiquidGlass.git

Or via Xcode » Package Dependencies… Select LiquidGlass and you’re done.

🚀 Quick start (SwiftUI)

Button("Glass Text") { }
    .liquidGlassBackground(cornerRadius: 60)

🖼 Example

ZStack {
    AnimatedColorsMeshGradientView()

    VStack(spacing: 20) {
        Text("Liquid Glass Button")
            .font(.title.bold())
            .foregroundColor(.white)

        Button("Click Me 🔥") {
            print("Tapped")
        }
        .foregroundStyle(.white)
        .font(.headline)
        .padding()
        .liquidGlassBackground(cornerRadius: 60)
    }
}
LiquidGlass live example

⚙️ Update modes

Mode What it does Best for
.continuous(interval:) Captures every n seconds. Animating backgrounds, parallax, fancy UIs.
.once Captures exactly one frame. Static dialogs, settings sheets.
.manual Capture only when you call invalidate() Power‑saving, custom triggers.

Via SwiftUI:

.liquidGlassBackground(updateMode: .once)

🎨 Shader & Customisation

  • Fragment shader – tweak Sources/LiquidGlass/Shaders/LiquidGlassShader.metal to adjust blur radius, refraction strength, tint or chromatic aberration. Two editable functions:
    • sampleBackground() – distort UVs / add ripple
    • postProcess() – lift saturation, add tint, vignette, bloom.
  • Performance knobs – lower snapshot interval, switch to .once, or optimise shader loops.

📈 Performance notes

  • Snapshot covers only the area behind the glass – minimal memory.
  • Layers above the glass are never hidden → no flicker.
  • Lazy redraw means nearly zero GPU when nothing changes.

🙋‍♂️ FAQ

The glass doesn’t update when I scroll.
Use .continuous(interval: 0.016) (≈60 fps) or trigger .manual’s invalidate() in scrollViewDidScroll.

🛡 License

MIT © 2025 • BarredEwe / Prefire


Made with ❤️ & Metal

About

Real‑time frosted glass and liquid‑like refraction for any SwiftUI view – no screenshots, no boilerplate.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Swift 71.7%
  • Metal 28.3%