Skip to main content

GLITCH_DISPLACE

Constant GLITCH_DISPLACE 

Source
pub const GLITCH_DISPLACE: &str = "// Port of gl-transitions/transitions/GlitchDisplace.glsl\n// Author: Matt DesLauriers\n// License: MIT\n// alpha2: upstream\'s unused voronoi is dropped, and the gray flash uses the taps\' alpha and\n// premultiplied gray, clamped, so the result stays premultiplied.\n\nfn glitch_displace_offset(tex: vec4f, uv: vec2f, dot_depth: f32, texture_depth: f32, strength: f32) -> vec2f {\n    var dis = tex * dot_depth + 1.0 - tex * texture_depth;\n    dis.x = dis.x - 1.0 + texture_depth * dot_depth;\n    dis.y = dis.y - 1.0 + texture_depth * dot_depth;\n    return uv + vec2f(dis.x, dis.y) * strength;\n}\n\nfn glitch_displace_ease1(t: f32) -> f32 {\n    if t == 0.0 || t == 1.0 { return t; }\n    if t < 0.5 { return 0.5 * exp2(20.0 * t - 10.0); }\n    return -0.5 * exp2(10.0 - t * 20.0) + 1.0;\n}\n\nfn glitch_displace_ease2(t: f32) -> f32 {\n    if t == 1.0 { return t; }\n    return 1.0 - exp2(-10.0 * t);\n}\n\nfn gl_transition(uv: vec2f) -> vec4f {\n    var color1 = gl_from_color(uv);\n    var color2 = gl_to_color(uv);\n    let val = glitch_displace_ease1(progress());\n    let disp = glitch_displace_offset(color1, uv, 0.33, 0.7, 1.0 - val);\n    let disp2 = glitch_displace_offset(color2, uv, 0.33, 0.5, glitch_displace_ease2(progress()));\n    let displaced1 = gl_to_color(disp);\n    let displaced2 = gl_from_color(disp2);\n    let gray = dot(min(displaced2, displaced1).rgb, vec3f(0.299, 0.587, 0.114));\n    let alpha = max(displaced1.a, displaced2.a);\n    let flash = vec4f(vec3f(min(gray * 2.0, alpha)), alpha);\n    color1 = mix(color1, flash, builtin_smoothstep(0.0, 0.5, progress()));\n    color2 = mix(color2, displaced1, builtin_smoothstep(1.0, 0.5, progress()));\n    return builtin_valid(mix(color1, color2, val));\n}\n";
Expand description

Color-driven displacement glitch transition body.