Variablur

1.1.0

Variable blur effects for SwiftUI, powered by Metal
daprice/Variablur

What's New

v1.1.0

2023-12-08T21:10:55Z
  • Improve documentation.
  • Use UV coordinates for sampling the mask image; the mask no longer has to be the same size as the view the effect is applied to.
  • Add a version of the modifier that takes an Image directly.
  • Note: the prioritizeVerticalPass parameter has been renamed to verticalPassFirst.

This version of the code is now included in the project that inspired it, Paul Hudson’s Inferno shader pack.

Variablur

With Variablur, you can create variable blur effects that you control with a mask. Because you draw the mask using a GraphicsContext, it can contain gradients, shapes, text, pre-rendered images, or anything else you can draw into a GraphicsContext.

You can create gradient or progressive blurs, vignettes, "blur shadows", or many other effects.

Example of a blurred snowflake background behind some demo UI.

More info

  • The blur radius is controlled per pixel for a true variable gaussian blur effect
  • Variablur uses 100% public API – it's just a Metal shader and a couple extensions to SwiftUI types
  • In my testing it runs smoothly even when applied to large, animated views or combined with other shaders. If performance is an issue, there's an option to lower the sample count. That said, I'm sure it could be optimized further and would be grateful for a PR that improves performance.
  • SwiftUI's visual effects can only be applied to pure SwiftUI views, and this library shares that limitation.

Examples

To see live examples of various effects you can achieve with different masks, clone this repository, open it in Xcode, and look in Sources/Variablur/View+variableBlur.swift for Xcode previews.

Usage with Swift Package Manager

Add Variablur to your project: https://github.com/daprice/Variablur

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Mon Dec 16 2024 19:13:26 GMT-1000 (Hawaii-Aleutian Standard Time)