Skip to main content

ROLLS

Constant ROLLS 

Source
pub const ROLLS: &str = "// Port of gl-transitions/transitions/Rolls.glsl\n// Author: Mark Craig\n// License: MIT\n// alpha2: `type` is the `corner` enum and `RotDown` is `rot_down`; the rolling frame\'s edges\n// are antialiased.\nconst ROLLS_PI = 3.14159265358979323846;\n\nfn gl_transition(uv: vec2f) -> vec4f {\n    let resolution_uv = vec2f(ratio(), 1.0);\n    let corner = params.corner;\n    let down = params.rot_down != 0u;\n    // Corners 0 and 1 turn one way, 2 and 3 the other; each mirrors uv so its pivot is (0, 0).\n    let turn = select(select(-ROLLS_PI, ROLLS_PI, down), select(ROLLS_PI, -ROLLS_PI, down), corner >= 2u);\n    let theta = turn / 2.0 * progress();\n    let flip_x = corner == 0u || corner == 3u;\n    let flip_y = corner == 2u || corner == 3u;\n    let uvi = vec2f(select(uv.x, 1.0 - uv.x, flip_x), select(uv.y, 1.0 - uv.y, flip_y));\n    let c1 = cos(theta);\n    let s1 = sin(theta);\n    let uv2 = vec2f(\n        uvi.x * resolution_uv.x * c1 - uvi.y * resolution_uv.y * s1,\n        uvi.x * resolution_uv.x * s1 + uvi.y * resolution_uv.y * c1,\n    ) / resolution_uv;\n    // The rotated frame\'s footprint per pixel, in its own uv.\n    let width = (abs(c1) + abs(s1)) / resolution();\n    let inside = builtin_interval_coverage(uv2.x, width.x) * builtin_interval_coverage(uv2.y, width.y);\n    let rolled = vec2f(select(uv2.x, 1.0 - uv2.x, flip_x), select(uv2.y, 1.0 - uv2.y, flip_y));\n    return mix(gl_to_color(uv), gl_from_color(rolled), inside);\n}\n";
Expand description

Picture rolling away around a corner transition body.