Created
March 5, 2026 18:10
-
-
Save radiofun/2bd9e4165fc6fc39cdd8e47f2d9bfbf1 to your computer and use it in GitHub Desktop.
Ripple Effect
This file contains hidden or 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
| #include <metal_stdlib> | |
| #include <SwiftUI/SwiftUI.h> | |
| using namespace metal; | |
| [[ stitchable ]] half4 simpleripple(float2 pos, SwiftUI::Layer l, float4 boundingRect, float time) { | |
| float2 size = boundingRect.zw; | |
| float2 uv = pos / size; | |
| float2 center = float2(0.5,0.5); | |
| float aspectratio = size.x / size.y; | |
| float speed = 0.1; | |
| float amplitude = 14; | |
| float frequency = 6; | |
| float decay = 0.1; | |
| float2 diff = uv - center; | |
| diff.x *= aspectratio; | |
| float distance = length(diff); | |
| float delay = distance / speed; | |
| time = max(0.0, time - delay); | |
| float rippleAmount = amplitude * sin(frequency * time) * exp(-decay * time); | |
| float2 n = normalize(uv - center); | |
| float2 newpos = uv * size; | |
| newpos += rippleAmount * n; | |
| half4 color= l.sample(newpos); | |
| color.rgb += 0.3 * (rippleAmount / amplitude) * color.a; | |
| return color; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment