Skip to content

Instantly share code, notes, and snippets.

View radiofun's full-sized avatar

Minsang Choi radiofun

View GitHub Profile
@radiofun
radiofun / DistortionTransition.metal
Created January 4, 2026 17:20
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));
@radiofun
radiofun / DistortionSampleView.swift
Created January 1, 2026 22:16
Distortion Sample view to use Distortion Shader
import SwiftUI
struct DistortionSampleView: View {
@State private var dragP : CGPoint = .init(x: -1000, y: -1000)
var body: some View {
ZStack {
// Black Background - replace with image, gradient, whatever you like.
Color.black
@radiofun
radiofun / Distortion.metal
Created January 1, 2026 22:14
Distortion Shader that is influenced by dragging position.
#include <metal_stdlib>
#include <SwiftUI/SwiftUI.h>
using namespace metal;
//Use DistortionSampleView.swift to try it out
//2026 Minsang Choi
[[ stitchable ]] half4 distortion(float2 pos, SwiftUI::Layer l, float4 boundingRect, float2 dragp) {
float2 delta = pos - dragp;