Skip to content

Instantly share code, notes, and snippets.

@radiofun
Last active February 15, 2026 09:13
Show Gist options
  • Select an option

  • Save radiofun/6bf67aa623d04beb8fbd0bd0cec4aad0 to your computer and use it in GitHub Desktop.

Select an option

Save radiofun/6bf67aa623d04beb8fbd0bd0cec4aad0 to your computer and use it in GitHub Desktop.
#include <metal_stdlib>
#include <SwiftUI/SwiftUI.h>
using namespace metal;
[[ stitchable ]] half4 simpledistort(float2 pos, SwiftUI::Layer l, float4 boundingRect, float progress, float distortion) {
float2 size = boundingRect.zw;
float2 uv = pos / size;
float2 center = float2(0.5, 0.5);
float2 delta = uv - center;
float distance = length(delta);
//Creating Liquid Circle-esque distortion
float outsideMask = smoothstep(distortion, 0.51, distance);
//Inner distortion
float2 ripple = float2(sin(delta.x * 3), cos(delta.y * 3));
float2 newpos = uv;
newpos -= ripple * distortion;
newpos += pow(outsideMask,2.0);
half4 color = l.sample(newpos * size);
//Blocking out pixels outside of radius
float holeMask = 1.0 - step(0.5, distance);
color *= holeMask;
return color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment