-
-
Save vedantgurav/fff05d316d620a34d70361983c3b2bd3 to your computer and use it in GitHub Desktop.
Apple Sports effect using Metal Shaders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// FlagView.swift | |
// VideoCamera | |
// | |
// Created by Vedant Gurav on 21/02/2024. | |
// | |
import SwiftUI | |
struct FlagView: View { | |
let leftColor = Color(hue: 1, saturation: 0.8, brightness: 0.7) | |
let rightColor = Color(hue: 0.6, saturation: 0.9, brightness: 0.8) | |
let startDate = Date() | |
var body: some View { | |
TimelineView(.animation) { _ in | |
ZStack { | |
LinearGradient(stops: [ | |
.init(color: leftColor, location: 0), | |
.init(color: leftColor, location: 0.35), | |
.init(color: leftColor.opacity(0.4), location: 0.6), | |
.init(color: .clear, location: 0.6) | |
], startPoint: .leading, endPoint: .trailing) | |
LinearGradient(stops: [ | |
.init(color: .clear, location: 0.3), | |
.init(color: rightColor.opacity(0.2), location: 0.4), | |
.init(color: rightColor, location: 0.65), | |
.init(color: rightColor, location: 1), | |
], startPoint: .leading, endPoint: .trailing) | |
} | |
.background(.black) | |
.blur(radius: 20) | |
.overlay { | |
Rectangle() | |
.fill(ImagePaint(image: Image("cloth"), scale: 1.5)) | |
.tint(.yellow) | |
.blendMode(.softLight) | |
.padding(-100) | |
.rotationEffect(.degrees(-20)) | |
.blur(radius: 0.4) | |
} | |
.scaleEffect(1.2) | |
.visualEffect { content, proxy in | |
content | |
.colorEffect( | |
ShaderLibrary.rippleColor( | |
.float(startDate.timeIntervalSinceNow), | |
.float2(proxy.size), | |
.float(2), | |
.float(0.2), | |
.float(0.025), | |
.float(0.25) | |
) | |
) | |
} | |
.drawingGroup() | |
.visualEffect { content, proxy in | |
content | |
.distortionEffect( | |
ShaderLibrary.ripple( | |
.float(startDate.timeIntervalSinceNow), | |
.float2(proxy.size), | |
.float(2), | |
.float(8), | |
.float(0.025), | |
.float(0.25), | |
.float(0.75) | |
), | |
maxSampleOffset: .zero | |
) | |
} | |
.ignoresSafeArea(edges: .all) | |
.statusBar(hidden: true) | |
.persistentSystemOverlays(.hidden) | |
} | |
} | |
} | |
#Preview { | |
FlagView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by the Apple Sports app