Skip to main content

FRAGMENT

Constant FRAGMENT 

Source
pub const FRAGMENT: &str = "// Port of gl-transitions/transitions/fragment.glsl\n// Author: lbl\n// License: MIT\n// alpha2: the shards\' sites and velocities are a table precomputed from PCG hashes\n// (builtin_hash3(shard, k, 0)) instead of upstream\'s fract(sin) random, so the loops call no\n// function; the nearest site compares squared distances.\nfn gl_transition(uv: vec2f) -> vec4f {\n    var sites = array<vec2f, 10>(\n        vec2f(0.49947667, 0.79509515), vec2f(0.78598905, 0.8087231),\n        vec2f(0.7057787, 0.054352045), vec2f(0.15288764, 0.93668187),\n        vec2f(0.144001, 0.630305), vec2f(0.7376622, 0.4944077),\n        vec2f(0.96819806, 0.06137538), vec2f(0.052491367, 0.2105034),\n        vec2f(0.84342873, 0.49684906), vec2f(0.5713028, 0.6560287),\n    );\n    // Upstream\'s normalize(direction) * speed.\n    var velocities = array<vec2f, 10>(\n        vec2f(0.16108474, 0.18276972), vec2f(0.008172598, 0.19987547),\n        vec2f(0.27351242, 0.006472239), vec2f(0.19284527, 0.22853737),\n        vec2f(0.18874688, 0.09974405), vec2f(0.091339566, 0.20896637),\n        vec2f(0.0029833287, 0.26016384), vec2f(0.26136217, 0.11754496),\n        vec2f(0.18530324, 0.21598965), vec2f(0.15319453, 0.20363313),\n    );\n    let duration = 8.0;\n    let travel = clamp(progress() * duration - 0.5, 0.0, duration);\n    var color = gl_to_color(uv);\n    for (var i = 0u; i < 10u; i++) {\n        // Shard `i` is site i\'s Voronoi cell of the outgoing picture, moved along its velocity.\n        let shifted = uv - velocities[i] * travel;\n        if shifted.x < 0.0 || shifted.x > 1.0 || shifted.y < 0.0 || shifted.y > 1.0 {\n            continue;\n        }\n        let own = shifted - sites[i];\n        let own_distance = dot(own, own);\n        var closest = true;\n        for (var j = 0u; j < 10u; j++) {\n            let other = shifted - sites[j];\n            if dot(other, other) < own_distance {\n                closest = false;\n                break;\n            }\n        }\n        if closest {\n            color = from_color(vec2f(shifted.x, 1.0 - shifted.y));\n            break;\n        }\n    }\n    return color;\n}\n";
Expand description

Voronoi shards flying away transition body.