Skip to content

Instantly share code, notes, and snippets.

@radiofun
Created January 4, 2026 17:20
Show Gist options
  • Select an option

  • Save radiofun/2df9324e4462272b07e760b4052851c5 to your computer and use it in GitHub Desktop.

Select an option

Save radiofun/2df9324e4462272b07e760b4052851c5 to your computer and use it in GitHub Desktop.
DistortionTransition.metal
[[ stitchable ]] half4 distortionWithScale(float2 pos, SwiftUI::Layer l, float4 boundingRect, float2 dragp, float progress) {
float2 delta = pos - dragp;
float dist = length(delta);
// Define the influence of the "force" from the drag point
float radius = 155.0; // Radius of effect
float strength = 0.8; // How much it pulls
// Influence peaks at 0.5, is 0 at 0.3 and 1.0 - you can customize these values.
float progressinfluence = smoothstep(0.3, 0.5, progress) * (1.0 - smoothstep(0.5, 1.0, progress));
// Smooth falloff using a Gaussian-like curve
float influence = exp(-dist * dist / (radius * radius)) * progressinfluence;
// Displace the sampling position.
float2 warpedPos = pos + delta * influence * strength;
// Apply scale centered on boundingRect
float2 center = float2(boundingRect[0] + boundingRect[2] * 0.5, boundingRect[1] + boundingRect[3] * 0.5);
float scale = max(0.001, progress); // Avoid division by zero
float2 samplePos = center + (warpedPos - center) / scale;
// Sample the color
half4 color = l.sample(samplePos);
return color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment