Skip to main content

WHIP_PAN

Constant WHIP_PAN 

Source
pub const WHIP_PAN: &str = "// Both pictures pushed along `direction`, blurred along it, most at the middle.\nfn whip_direction(index: u32) -> vec2f {\n    if index == 0u { return vec2f(-1.0, 0.0); }\n    if index == 1u { return vec2f(1.0, 0.0); }\n    if index == 2u { return vec2f(0.0, -1.0); }\n    return vec2f(0.0, 1.0);\n}\n\nfn transition(uv: vec2f) -> vec4f {\n    let taps = u32(clamp(max_filter_samples(), 1.0, 64.0));\n    let d = whip_direction(params.direction);\n    let axis = abs(d);\n    let texel = dot(axis, 1.0 / resolution());\n    // Never under a pixel, so the seam between the pictures stays smooth.\n    let streak = max(params.blur * 0.5 * sin(3.14159265 * progress()), texel);\n    // The incoming picture follows the outgoing one in; ahead of the outgoing one its own edge\n    // repeats.\n    let forward = dot(d, axis) > 0.0;\n    var sum = vec4f(0.0);\n    for (var i = 0u; i < taps; i++) {\n        let q = uv - d * progress() + d * (streak * ((f32(i) + 0.5) / f32(taps) - 0.5));\n        let along = dot(q, axis);\n        let incoming = select(along > 1.0, along < 0.0, forward);\n        sum += select(from_color(q), to_color(q + d), incoming);\n    }\n    return sum / f32(taps);\n}\n";
Expand description

Motion-blurred push transition body.