Skip to content

Repository files navigation

metal-LIC-demo-small.mp4

metal-LIC

GPU implementation of the line integral convolution (LIC) algorithm on Apple Silicon, written in Swift + Metal. Capable of real-time performance at 4k resolution (~40 fps in simple tests on my Apple M1 Pro machine).

What it does

It takes an input texture and a vector field, traces streamlines via RK2 integration with a Hann-windowed kernel, and outputs a grayscale LIC image. The entire pipeline runs as a Metal compute shader with no CPU readback.

Thanks to the performance of this implementation, it is possible to assign time-dynamics to the input texture that is getting convolved, giving a host of possible dynamic visualizations of the (static) vector field.

Performance

Measured GPU time on M1 Pro, single pass, kernel length 30 pixels:

Resolution Uniform field Vortex field
1080p 238 fps 179 fps
2048x2048 118 fps 88 fps
3840x2160 60 fps 46 fps

Throughput scales linearly with kernel length.

Usage

Swift Package Manager library. Add as a dependency:

.package(url: "https://github.com/<you>/metal-LIC", branch: "main")

The package provides LICEncoder for single-shot encoding and LICDispatcher for pipelined multi-buffered dispatch.

Demo app

LICDemo is a SwiftUI app that pairs the LIC engine with a forest fire cellular automaton to give time-dependent noise. This lets you run real-time simulations. Run it from Xcode or swift run LICDemo.

About

GPU implementation of Line Integral Convolution for Mac

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages