Holo Foil

by MusicBar, progress bar

A strip of iridescent holographic foil is laid down to the playhead, its rainbow sheen sweeping and shifting with the spectrum, glitter twinkling across the emboss, and the sparkle on top bursting into rays on every beat.

0 downloads Download file, 7.0 KB
How it installs, its SHA-256 and its code

Click Apply: MusicBar downloads it, checks its SHA-256 and puts it on the taskbar, or just puts it on if it already has it. Needs MusicBar 1.8 or newer.

SHA-256 abf0f08ff849cc9cc23fd8559ce79167db8377179f5126735992756340f05e6e

//! name: Holo Foil
//! author: MusicBar
//! kind: progress
//! description: A strip of iridescent holographic foil is laid down to the playhead under a sparkle, its rainbow sheen sweeping and shifting with the spectrum, glitter twinkling in the emboss and bursting on every beat.

float hash2(float2 p) { float3 q = frac(float3(p.x, p.y, p.x) * 0.1031); q += dot(q, q.yzx + 33.33); return frac((q.x + q.y) * q.z); }

float vnoise(float2 p)
{
    float2 i = floor(p), f = frac(p);
    f = f * f * (3.0 - 2.0 * f);
    return lerp(lerp(hash2(i), hash2(i + float2(1, 0)), f.x), lerp(hash2(i + float2(0, 1)), hash2(i + float2(1, 1)), f.x), f.y);
}

// Lays a color over what is there (premultiplied light, and how much of the pixel it covers).
void layer(inout float3 acc, inout float cover, float3 rgb, float a)
{
    a = saturate(a);
    acc = rgb * a + acc * (1.0 - a);
    cover = a + cover * (1.0 - a);
}

// The foil's color for a phase t: the three palette colors in a loop, mixed with a true rainbow.
float3 holo(float t)
{
    float k = frac(t) * 3.0;
    float f = smoothstep(0.0, 1.0, frac(k));
    float3 c = k < 1.0 ? lerp(colorA.rgb, colorB.rgb, f) : (k < 2.0 ? lerp(colorB.rgb, colorC.rgb, f) : lerp(colorC.rgb, colorA.rgb, f));
    return lerp(c, 0.5 + 0.5 * cos(6.2832 * (t * 2.0 + float3(0.0, 0.33, 0.67))), 0.2);
}

// Rounded box distance (half size b, corner r).
float boxD(float2 p, float2 b, float r) { float2 d = abs(p) - b + r; return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - r; }

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float u = size.y;
    float2 px = float2(uv.x * size.x, rise(uv) * u);          // pixels: along the bar, up from the screen edge
    float cy = 0.5 * u, hh = 0.28 * u, cr = 0.17 * u;
    float x0 = 0.2 * u;
    float head = max(progress * size.x, x0 + 2.0 * cr);
    float sp = spectrum(saturate(px.x / size.x));
    float3 acc = float3(0, 0, 0);
    float cover = 0;

    // Where the foil is still to come: a faint clear liner with a thin edge.
    float dTrack = boxD(px - float2(0.5 * size.x, cy), float2(0.5 * size.x - x0, hh), 0.06 * u);
    layer(acc, cover, float3(0.85, 0.88, 0.95), smoothstep(0.5, -0.5, dTrack) * 0.06);
    layer(acc, cover, lerp(colorB.rgb, float3(1, 1, 1), 0.4), smoothstep(1.0, 0.0, abs(dTrack + 0.5)) * 0.3);

    // The foil laid so far, up to the middle of the curl.
    float xe = head - cr;
    float dFoil = boxD(px - float2(0.5 * (x0 + xe), cy), float2(0.5 * (xe - x0), hh), 0.06 * u);
    float foil = smoothstep(0.5, -0.5, dFoil);

    // A soft emboss of little diamonds: each face tilts the light a touch.
    float s = 0.3 * u;
    float2 dq = float2(frac((px.x + px.y) / s) - 0.5, frac((px.x - px.y) / s) - 0.5);
    float2 n = float2(sign(dq.x) + sign(dq.y), sign(dq.x) - sign(dq.y)) * 0.5;

    // The sheen: a diagonal band of light sweeping along; the hues slide through it and the spectrum shifts them.
    float sweep = frac(time * 0.15) * (head + 8.0 * u) - 4.0 * u;
    float dS = (px.x - sweep + (px.y - cy) * 1.4) / u;
    float crumple = vnoise(px / (0.9 * u)) + 0.5 * vnoise(px / (0.35 * u));
    float t = px.x / (6.0 * u) + 0.35 * crumple + 0.45 * sp + 0.25 * dS * exp(-dS * dS * 0.15) + time * 0.03;
    float grating = sin((px.x - 0.6 * px.y) * 6.2832 / max(2.0, 0.03 * u));             // fine diffraction lines
    t += 0.02 * grating;
    float crease = smoothstep(0.05, 0.0, min(abs(dq.x), abs(dq.y)) * s / u);

    // Chrome-like depth: the foil turns from bright pastel into a deep violet-tinted shade as it tilts away.
    float tilt = 0.5 + 0.5 * sin(6.2832 * (px.x / (2.6 * u) + 0.45 * crumple)) + 0.045 * dot(n, float2(-0.5, 0.7)) + 0.03 * grating;
    float3 base = holo(t);
    base = saturate(lerp(dot(base, float3(0.3, 0.5, 0.2)), base, 1.35));
    float3 deep = holo(t + 0.4) * 0.6 + float3(0.06, 0.02, 0.16);
    float3 fc = lerp(deep, lerp(base, float3(1, 1, 1), 0.12) * 1.05, saturate(0.2 + 0.8 * tilt)) + crease * 0.045;
    float sheen = exp(-dS * dS * 2.2) * (0.6 + 0.4 * level);
    fc = lerp(fc, float3(1, 1, 1), sheen * 0.75) + holo(t + 0.5) * exp(-dS * dS * 0.5) * 0.2;
    layer(acc, cover, lerp(colorA.rgb, colorB.rgb, 0.5) * 0.2, smoothstep(1.0, -0.5, dFoil - 1.2) * 0.85);
    layer(acc, cover, fc, foil);
    layer(acc, cover, float3(1, 1, 1), smoothstep(1.0, 0.0, abs(dFoil + 1.0)) * foil * (0.3 + 0.5 * sheen));

    // Glitter: one fleck per cell that twinkles now and then; on the beat half of them flare at once.
    float gs = 0.21 * u;
    float2 gc = floor(px / gs);
    float h = hash2(gc + 3.1), h2 = hash2(gc * 1.7 + 9.4);
    float2 gd = abs(px - (gc + 0.3 + 0.4 * float2(h, h2)) * gs);
    float tw = pow(saturate(sin(time * (1.5 + 2.5 * h) + h2 * 40.0)), 10.0) * step(0.35, h);
    tw = max(tw, saturate(beat * 1.5) * step(0.4, h2)) * (0.8 + 0.5 * sheen);
    float arm = 0.13 * u * (0.4 + 0.8 * tw);
    float star = exp(-length(gd) / (0.028 * u)) * 1.3 + (exp(-gd.y / 0.7) + exp(-gd.x / 0.7)) * saturate(1.0 - max(gd.x, gd.y) / arm);
    layer(acc, cover, lerp(holo(h * 3.0 + time * 0.2), float3(1, 1, 1), 0.65), star * tw * foil);

    // The curl at the playhead: the foil lifts and rolls over, showing its silver back with a hard glint.
    float cx = (px.x - (head - cr)) / cr;
    float inCurl = smoothstep(0.5, -0.5, boxD(float2(px.x - (head - cr), px.y - cy), float2(cr, hh), 0.04 * u));
    float nz = sqrt(saturate(1.0 - cx * cx));
    float3 front = holo(t - cx * 0.6 + 0.2);
    front = saturate(lerp(dot(front, float3(0.3, 0.5, 0.2)), front, 1.4));
    float3 back = cx < 0.0 ? front * (0.62 + 0.45 * nz) : lerp(float3(0.42, 0.45, 0.55), float3(0.92, 0.94, 1.0), nz);
    back += float3(1, 1, 1) * pow(saturate(1.0 - abs(cx + 0.2) * 5.0), 2.0) * 0.85;
    layer(acc, cover, float3(0, 0, 0.02), exp(-max(px.x - head, 0.0) / (0.1 * u)) * step(head - 0.1 * u, px.x) * smoothstep(hh + 0.08 * u, hh - 0.04 * u, abs(px.y - cy)) * 0.4);
    layer(acc, cover, lerp(colorA.rgb, colorB.rgb, 0.5) * 0.25, smoothstep(1.0, -0.5, boxD(float2(px.x - (head - cr), px.y - cy), float2(cr, hh), 0.04 * u) - 1.2) * 0.9);
    layer(acc, cover, back, inCurl);

    // The sparkle riding the curl: a four-point star that turns gently and swells on the beat.
    float2 sq = px - float2(head - 0.1 * u, cy + 0.17 * u);
    float sa = 0.25 * sin(time * 0.8);
    sq = float2(cos(sa) * sq.x - sin(sa) * sq.y, sin(sa) * sq.x + cos(sa) * sq.y);
    float R = 0.27 * u * (1.0 + 0.4 * beat + 0.1 * sin(time * 3.0));
    float dStar = (sqrt(abs(sq.x) / R) + sqrt(abs(sq.y) / R) - 1.0) * R * 0.5;
    layer(acc, cover, lerp(colorC.rgb, float3(1, 1, 1), 0.3), exp(-max(length(sq) - 0.05 * u, 0.0) / (0.12 * u)) * (0.45 + 0.5 * beat));
    layer(acc, cover, lerp(colorA.rgb, colorB.rgb, 0.5) * 0.3, smoothstep(0.5, -0.5, dStar - 1.0) * 0.8);
    layer(acc, cover, lerp(float3(1, 1, 1), holo(time * 0.2), smoothstep(0.0, R * 0.5, length(sq)) * 0.6), smoothstep(0.5, -0.5, dStar));

    // The beat burst: thin rays fanning out of the sparkle.
    float ray = pow(abs(cos(atan2(sq.y, sq.x) * 4.0 + 0.785)), 40.0) * exp(-length(sq) / (0.4 * u));
    layer(acc, cover, lerp(colorC.rgb, float3(1, 1, 1), 0.5), ray * beat);

    return paint(acc / max(cover, 0.001), cover);
}