/SwiftFX

SwiftUI Effects

Primary LanguageSwiftMIT LicenseMIT

Powered by Metal with AsyncGraphics

SwiftFX is a bit heavy (especially for animating content). For effects in a production app, I recommend using AsyncGraphics directly. The goal for this package is to show the kinds of effects that are possible to create in SwiftUI with Metal.

Install

.package(url: "https://github.com/heestand-xyz/SwiftFX", from: "2.0.0")

Example

import SwiftUI
import SwiftFX
struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundStyle(.tint)
            Text("Hello, world!")
        }
        .padding()
        .fxEdge()
        .fxBlur(style: .zoom, radius: 0.5)
    }
}
Text("Hello, World!") .fxEdge() .fxBlur(style: .zoom)

In version 2.0.0 spatial values are not relative anymore, they are absolute in pixel space

Effects

func fxBlur(style, radius, angle, position, quality) -> FXView

func fxEdge(strength, distance) -> FXView

func fxRainbowBlur(radius) -> FXView

func fxClamp(low, high) -> FXView

func fxKaleidoscope(divisions, mirror) -> FXView

func fxBrightness(_) -> FXView

func fxDarkness(_) -> FXView

func fxContrast(_) -> FXView

func fxGamma(_) -> FXView

func fxInvert() -> FXView

func fxOpacity(_) -> FXView

func fxQuantize(fraction) -> FXView

func fxSharpen(_) -> FXView

func fxSlope(_) -> FXView

func fxThreshold(_) -> FXView

func fxRange(inLow, inHigh, outLow, outHigh) -> FXView

func fxSaturation(_) -> FXView

func fxMonochrome() -> FXView

func fxHue(_) -> FXView

func fxSepia(color) -> FXView

func fxFlipX() -> FXView

func fxFlipY() -> FXView

func fxFlopLeft() -> FXView

func fxFlopRight() -> FXView

Custom Effects

import AsyncGraphics
Text("Custom")
    .fx { graphic in
        let noise: Graphic = try await .coloredNoise(resolution: graphic.resolution)
        return try await graphic.displaced(with: noise, offset: 10)
    }