r/SwiftUI • • 5d ago

Tutorial SwiftUI + Metal Foil Effect: Source Code on GitHub

20 Upvotes

2 comments sorted by

2

u/LividIllustrator8915 5d ago

Clean visual effect. Are you driving the light angle strictly off a drag gesture or touch coordinates, or did you wire in CoreMotion to tilt the specular reflections based on device pitch and roll?

Also curious if you had to do anything specific around frame pacing on 120Hz ProMotion displays. Metal shaders via .distortionEffect or custom layer modifiers usually look great, but if the parameter updates trigger continuous SwiftUI view re-evaluations, it can sometimes hitch during rapid swipes.

2

u/zach-builds 2d ago

Thank you! It's pretty simple actually, no CoreMotion or lighting etc. It uses .onContinuousHover to paint a soft radial gradient on the pointer + rotation3DEffect. The shader math is adapted from bpisano’s Sticker repo. And it runs on SwiftUI’s animation system (nothing specific for ProMotion).