Skip to main content

HSV_FADE

Constant HSV_FADE 

Source
pub const HSV_FADE: &str = "// Port of gl-transitions/transitions/HSVfade.glsl\n// Author: nwoeanhinnogaehr\n// License: MIT\n// alpha2: HSV of the straight color, alpha mixed instead of opaque. Hue and saturation mix as a\n// chroma vector to stay continuous across the hue wrap and through grays. Saturation fades out\n// below a tenth of white.\nfn hsv_fade_hsv(color: vec4f) -> vec3f {\n    let hsv = builtin_rgb_to_hsv(builtin_straight(color));\n    return vec3f(hsv.x, hsv.y * builtin_smoothstep(0.0, 0.1, hsv.z), hsv.z);\n}\n\nfn gl_transition(uv: vec2f) -> vec4f {\n    let outgoing = gl_from_color(uv);\n    let incoming = gl_to_color(uv);\n    let a = hsv_fade_hsv(outgoing);\n    let b = hsv_fade_hsv(incoming);\n    let chroma_a = a.y * vec2f(cos(a.x * 6.28318531), sin(a.x * 6.28318531));\n    let chroma_b = b.y * vec2f(cos(b.x * 6.28318531), sin(b.x * 6.28318531));\n    let chroma = mix(chroma_a, chroma_b, progress());\n    // No chroma, no hue: atan2(0, 0) is undefined.\n    let hue = select(0.0, atan2(chroma.y, chroma.x) / 6.28318531, dot(chroma, chroma) > 0.0);\n    let m = vec3f(hue, length(chroma), mix(a.z, b.z, progress()));\n    let alpha = mix(outgoing.a, incoming.a, progress());\n    return vec4f(builtin_hsv_to_rgb(m) * alpha, alpha);\n}\n";
Expand description

Cross-fade through hue, saturation and value transition body.