### Animated Shader Effect ViewModifier Source: https://github.com/krispuckett/swiftuishaders/blob/main/AGENTS.md This ViewModifier applies an animated shader effect. It uses `TimelineView(.animation)` to get the elapsed time and passes both the content size and the time to the shader function via the `visualEffect` modifier. ```swift struct _AnimatedShaderEffect: ViewModifier { let maxSampleOffset: CGSize let shader: (CGSize, Float) -> Shader func body(content: Content) -> some View { TimelineView(.animation) { context in let t = Float(context.date.timeIntervalSinceReferenceDate .truncatingRemainder(dividingBy: 3600)) // bounded to keep float precision content.visualEffect { view, proxy in view.layerEffect(shader(proxy.size, t), maxSampleOffset: maxSampleOffset) } } } } ``` -------------------------------- ### Applying Shader with Generic Arguments Source: https://github.com/krispuckett/swiftuishaders/blob/main/AGENTS.md This snippet demonstrates a less verbose, generic approach to applying shaders by assembling arguments dynamically. It requires careful handling of time and point parameters. ```swift content.layerEffect( ShaderLibrary.bundle(.module)[dynamicMember: shader.metal](arguments), maxSampleOffset: CGSize(width: 64, height: 64) ) ``` -------------------------------- ### Accessing Shaders in Swift Source: https://github.com/krispuckett/swiftuishaders/blob/main/AGENTS.md This Swift code demonstrates how to access and instantiate a shader from the SwiftUIShaders package's compiled Metal library. Ensure the correct bundle and shader name are used. ```swift ShaderLibrary.bundle(.module).bcs_name(.float2(size), .float(t), .float(param1), ...) ``` -------------------------------- ### Using Touch-Driven Shaders with GeometryReader Source: https://github.com/krispuckett/swiftuishaders/blob/main/README.md This snippet demonstrates how to use interaction-driven shaders like `bcsRefractLens` by capturing touch input and normalizing it using `GeometryReader`. It's useful for creating reactive visual effects based on user interaction. ```swift import SwiftUI struct ContentView: View { @State private var touch: UnitPoint = .center var body: some View { GeometryReader { geo in myView .bcsRefractLens(touchPos: touch, lensRadius: 0.3) .gesture(DragGesture(minimumDistance: 0).onChanged { v in touch = UnitPoint(x: v.location.x / geo.size.width, y: v.location.y / geo.size.height) }) } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } // Placeholder for myView struct myView: View { var body: some View { Rectangle() .fill(Color.blue) .frame(width: 200, height: 200) } } // Placeholder for bcsRefractLens modifier extension View { func bcsRefractLens(touchPos: UnitPoint, lensRadius: CGFloat) -> some View { self.modifier(RefractLensModifier(touchPos: touchPos, lensRadius: lensRadius)) } } struct RefractLensModifier: ViewModifier { let touchPos: UnitPoint let lensRadius: CGFloat func body(content: Content) -> some View { content } } ``` -------------------------------- ### Add Swift Package Dependency Source: https://github.com/krispuckett/swiftuishaders/blob/main/README.md Add SwiftUIShaders to your project via Swift Package Manager in Xcode or by updating your Package.swift file. ```swift .package(url: "https://github.com/krispuckett/SwiftUIShaders.git", from: "1.0.0") ``` -------------------------------- ### Applying Shader with Dynamic Arguments Source: https://github.com/krispuckett/swiftuishaders/blob/main/AGENTS.md This snippet shows how to apply a shader dynamically using a switch statement on the modifier name. It is type-safe but more verbose. ```swift content.layerEffect( ShaderLibrary.bundle(.module)[dynamicMember: shader.metal](params), maxSampleOffset: CGSize(width: 64, height: 64) ) ``` -------------------------------- ### Apply Aurora Shader Source: https://github.com/krispuckett/swiftuishaders/blob/main/README.md Apply an ambient animated glow effect (Aurora shader) to a view. This is an animated shader that runs itself. ```swift bookCover .bcsAurora() // ambient animated glow ``` -------------------------------- ### Swift Wrapper for a New Shader Source: https://github.com/krispuckett/swiftuishaders/blob/main/AGENTS.md Defines a SwiftUI View modifier for a new shader effect. Includes parameters for strength and maximum sample offset. Use _StaticShaderEffect for non-animated effects. ```swift /// My Effect. What it does. /// - Parameter strength: 0-10: how strong func bcsMyEffect(strength: Float = 5, maxSampleOffset: CGSize = CGSize(width: 64, height: 64)) -> some View { modifier(_AnimatedShaderEffect(maxSampleOffset: maxSampleOffset) { size, t in ShaderLibrary.bundle(.module).bcs_myEffect( .float2(size), .float(t), .float(strength) ) }) } ``` -------------------------------- ### SwiftUI LayerEffect Shader Signature Source: https://github.com/krispuckett/swiftuishaders/blob/main/AGENTS.md This is the standard signature for a stitchable Metal fragment shader used with SwiftUI's layerEffect. Arguments after 'layer' are supplied by the Swift code. ```metal [[ stitchable ]] half4 bcs_name( float2 position, SwiftUI::Layer layer, float2 size, float time, float param1, ... ) { ... } ``` -------------------------------- ### Apply Chromatic Split Shader Source: https://github.com/krispuckett/swiftuishaders/blob/main/README.md Apply a chromatic split shader to a Text view. This effect can be customized with spread and angle parameters. ```swift Text("Chapter One") .font(.largeTitle) .bcsChromaticSplit(spread: 8, angle: .pi / 4) ``` -------------------------------- ### Apply Holographic Shader Source: https://github.com/krispuckett/swiftuishaders/blob/main/README.md Apply an animated, self-driving holographic shader to an Image view. This modifier uses TimelineView for animation. ```swift import SwiftUI import SwiftUIShaders struct ContentView: View { var body: some View { Image("book-cover") .resizable() .scaledToFit() .bcsHolographic(intensity: 0.6, scale: 12, speed: 1.2) // animated, self-driving } } ``` -------------------------------- ### Apply Emboss Shader Source: https://github.com/krispuckett/swiftuishaders/blob/main/README.md Apply a static relief effect (Emboss shader) to a view. This modifier is for static effects and does not animate. ```swift myView .bcsEmboss(strength: 3) // static relief ``` -------------------------------- ### Static Shader Effect ViewModifier Source: https://github.com/krispuckett/swiftuishaders/blob/main/AGENTS.md This ViewModifier applies a static shader effect. It takes the shader function and the maximum sample offset, then uses the `visualEffect` modifier to apply the shader to the content, passing the proxy's size to the shader. ```swift struct _StaticShaderEffect: ViewModifier { let maxSampleOffset: CGSize let shader: (CGSize) -> Shader func body(content: Content) -> some View { content.visualEffect { view, proxy in view.layerEffect(shader(proxy.size), maxSampleOffset: maxSampleOffset) } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.