Super Meter

by MusicBar, progress bar

A fighting-game super gauge in a beveled metal frame charges with the song: crackling energy with flickering lightning fills three segments, each one flashes as it fills up, and sparks fly off the front on every beat.

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 01d9c3b97f7576831f7f67948f218fd2fb8d61e396666a9e914cb5d6bf57c43d

//! name: Super Meter
//! author: MusicBar
//! kind: progress
//! description: A fighting-game super gauge in a beveled metal frame charges with the song: crackling energy with flickering lightning fills three segments, each one flashes as it fills up, and sparks fly off the front on every beat.

float hash1(float n) { return frac(sin(n * 127.1 + 311.7) * 43758.5453); }
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); }

// Smooth value noise for the churning energy.
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);
}

// A jagged lightning line: random heights joined by straight runs, a coarse and a fine zigzag.
float bolt(float x, float seed)
{
    float a = floor(x * 2.6), b = floor(x * 9.0);
    return 0.5 + 0.3 * (lerp(hash1(a + seed), hash1(a + 1.0 + seed), frac(x * 2.6)) - 0.5) + 0.1 * (lerp(hash1(b + seed * 1.7), hash1(b + 1.0 + seed * 1.7), frac(x * 9.0)) - 0.5);
}

// 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); }

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float u = size.y;
    float2 px = float2(uv.x * size.x, (1.0 - uv.y) * size.y);   // pixels, screen-up
    float head = progress * size.x;
    float y = px.y / u;
    float s = px.x - (px.y - 0.5 * u) * 0.45;                    // along the gauge, its forward lean taken out
    float segW = size.x / 3.0;
    float seg = clamp(floor(s / segW), 0.0, 2.0);
    float3 segCol = seg < 0.5 ? colorA.rgb : (seg < 1.5 ? colorB.rgb : colorC.rgb);
    float3 curCol = head < segW ? colorA.rgb : (head < 2.0 * segW ? colorB.rgb : colorC.rgb);   // the charge level so far
    float3 white = float3(1, 1, 1), acc = float3(0, 0, 0);
    float cover = 0;
    float inCh = smoothstep(-0.5, 0.5, px.y - 0.27 * u) * smoothstep(0.5, -0.5, px.y - 0.73 * u);
    float filled = smoothstep(0.5, -0.5, s - head);

    // Crossing a divider: the filled gauge flashes and a shock ring leaves the divider.
    float d1 = (head - segW) / u, d2 = (head - 2.0 * segW) / u;
    float dd = d2 >= 0.0 ? d2 : d1;
    float flash = step(0.0, dd) * exp(-dd / 0.55);

    // The empty channel: dark glass with faint slanted ticks.
    float tick = smoothstep(1.0, 0.0, abs(frac(s / (0.5 * u) + 0.5) - 0.5) * 0.5 * u);
    layer(acc, cover, float3(0.03, 0.03, 0.07), inCh * (1.0 - filled) * 0.24);
    layer(acc, cover, lerp(colorA.rgb, white, 0.5), inCh * (1.0 - filled) * tick * 0.14);

    // The energy: churning plasma in the segment's color, hot veins, brighter toward the front,
    // and a sheen sweeping over finished segments so a full bar looks charged.
    float2 e = float2(s / u, y);
    float n = vnoise(float2(e.x * 3.0 - time * 3.2, e.y * 5.0 + time * 0.8)) * 0.65 + vnoise(float2(e.x * 8.0 - time * 6.5, e.y * 11.0 - time * 1.3)) * 0.35;
    float vein = pow(saturate(1.0 - abs(n - 0.5) * 5.0), 3.0);
    float core = saturate(1.0 - abs(y - 0.5) / 0.23);
    float hot = exp(-max(head - s, 0.0) / (1.4 * u));
    float3 energy = segCol * (0.3 + 0.8 * n) * (0.7 + 0.4 * core) + lerp(segCol, white, 0.6) * vein * (0.45 + 0.5 * level);
    energy += white * (0.3 * hot * core + 0.6 * flash);
    float sheen = exp(-abs(frac((s - px.y * 0.8) / (5.0 * u) - time * 0.35) - 0.5) * 40.0) * step(seg + 1.0, head / segW);
    layer(acc, cover, energy + lerp(segCol, white, 0.7) * sheen * 0.5, inCh * filled);

    // Lightning: two jagged bolts that re-strike thirteen times a second, more of them when the song is loud.
    float seed = floor(time * 13.0);
    float b1 = abs(y - bolt(e.x, seed * 3.1)) * u, b2 = abs(y - bolt(e.x + 17.0, seed * 5.3 + 9.0)) * u;
    float on1 = step(hash1(floor(e.x / 1.6) + seed * 0.37), 0.3 + 0.35 * level);
    float on2 = step(hash1(floor(e.x / 1.1 + 7.0) + seed * 0.71), 0.2 + 0.35 * level + 0.4 * beat);
    float bolts = on1 * (smoothstep(1.3, 0.3, b1) + 0.35 * exp(-b1 / 2.5)) + on2 * (smoothstep(1.1, 0.2, b2) + 0.3 * exp(-b2 / 2.0));
    layer(acc, cover, lerp(lerp(segCol, white, 0.75), white, smoothstep(0.5, 1.0, bolts)), saturate(bolts) * inCh * filled * (0.6 + 0.4 * hot));

    // The glass tube over the channel: a soft reflection line along its top.
    layer(acc, cover, white, smoothstep(1.2, 0.0, abs(px.y - 0.675 * u)) * inCh * lerp(0.12, 0.3, filled));

    // The metal rails: rounded bars lit from above, dull ahead and lit by the energy below them where it is charged.
    float tTop = (y - 0.73) / 0.1, tBot = (0.27 - y) / 0.1;
    float onTop = smoothstep(-0.5, 0.5, px.y - 0.73 * u) * smoothstep(0.5, -0.5, px.y - 0.83 * u);
    float onBot = smoothstep(-0.5, 0.5, 0.27 * u - px.y) * smoothstep(0.5, -0.5, 0.17 * u - px.y);
    float tr = saturate(onTop > onBot ? tTop : 1.0 - tBot);
    float3 steel = lerp(float3(0.62, 0.65, 0.72), colorB.rgb, 0.15);
    float3 rail = steel * (0.3 + 0.7 * smoothstep(0.0, 0.75, tr)) + white * 0.55 * exp(-abs(tr - 0.72) / 0.07);
    rail *= 1.0 - 0.6 * smoothstep(0.85, 1.0, tr) - 0.5 * smoothstep(0.15, 0.0, tr);
    rail = (rail + segCol * 0.55 * filled * exp(-abs(onTop > onBot ? tTop : tBot) / 0.25)) * lerp(0.6, 1.0, filled);
    float railS = smoothstep(-0.5, 0.5, s - 0.3 * u) * smoothstep(0.5, -0.5, s - size.x + 0.3 * u);
    layer(acc, cover, rail, saturate(onTop + onBot) * railS);

    // Dividers between the three segments, each with a stock gem on the top rail that lights once its segment is full.
    float bk = s < 1.5 * segW ? segW : 2.0 * segW;
    float dv = abs(s - bk);
    float passed = step(bk, head);
    float3 gemCol = s < 1.5 * segW ? colorA.rgb : colorB.rgb;
    layer(acc, cover, steel * 0.15, smoothstep(0.5, -0.5, dv - 0.055 * u) * inCh);
    layer(acc, cover, steel * (0.5 + 0.6 * smoothstep(0.04 * u, 0.0, dv)) + gemCol * passed * 0.6, smoothstep(0.5, -0.5, dv - 0.035 * u) * inCh);
    float2 gp = (px - float2(bk + 0.135 * u, 0.79 * u)) / u;
    float gemD = (abs(gp.x) + abs(gp.y) - 0.14) * 0.707 * u;
    layer(acc, cover, gemCol, passed * exp(-max(gemD, 0.0) / (0.14 * u)) * (0.65 + 0.35 * beat));
    layer(acc, cover, steel * 0.2, smoothstep(0.5, -0.5, gemD - 1.3));
    float facet = gp.x < 0.0 ? (gp.y > 0.0 ? 1.0 : 0.55) : (gp.y > 0.0 ? 0.75 : 0.35);   // four cut faces, lit from the upper left
    float3 gem = lerp(float3(0.16, 0.16, 0.24), lerp(gemCol, white, 0.2), passed) * (0.45 + 0.75 * facet);
    gem += white * smoothstep(0.035, 0.012, length(gp - float2(-0.035, 0.04))) * (0.4 + 0.5 * passed);
    layer(acc, cover, gem, smoothstep(0.5, -0.5, gemD + 0.012 * u));

    // The shock ring from the divider just crossed.
    float ring = abs(length(px - float2(d2 >= 0.0 ? 2.0 * segW : segW, 0.5 * u)) / u - (0.15 + dd * 1.4));
    layer(acc, cover, lerp(segCol, white, 0.6), exp(-dd / 0.35) * smoothstep(0.05, 0.0, ring) * step(0.0, dd));

    // End caps: pointed beveled plates with a gilded inlay and two rivets; the left one holds a power orb
    // in the color of the charge so far, pulsing with the music; the right one lights when the song ends.
    float ay = abs(px.y - 0.5 * u);
    float capL = max(ay - 0.42 * u, (s - 0.62 * u + ay * 0.55) * 0.876);
    float capR = max(ay - 0.42 * u, (size.x - s - 0.62 * u + ay * 0.55) * 0.876);
    float capD = min(capL, capR);
    float3 plate = steel * (0.3 + 0.5 * y) * (1.0 - 0.08 * frac(px.y / 2.0) * 2.0);
    plate = lerp(plate, px.y > 0.5 * u ? white * 0.95 : steel * 0.22, smoothstep(-0.07 * u, 0.0, capD) * 0.6);
    plate = lerp(plate, lerp(colorC.rgb, white, 0.25), smoothstep(1.0, 0.2, abs(capD + 0.11 * u)) * 0.85);
    float2 oc = float2(capL < capR ? 0.3 * u : size.x - 0.3 * u, 0.5 * u);
    float2 rv = abs(px - oc - float2(capL < capR ? 0.26 * u : -0.26 * u, 0.0)) - float2(0.0, 0.29 * u);
    plate = lerp(plate, steel * 1.25, smoothstep(0.045 * u, 0.025 * u, length(rv)));
    layer(acc, cover, float3(0.04, 0.04, 0.06), smoothstep(0.5, -0.5, capD - 1.3));
    layer(acc, cover, plate, smoothstep(0.5, -0.5, capD));
    float od = length(px - oc), orR = 0.19 * u;
    float lit = capL < capR ? 1.0 : step(0.999, progress);
    layer(acc, cover, float3(0.02, 0.02, 0.03), smoothstep(0.5, -0.5, od - orR - 0.07 * u));
    layer(acc, cover, steel * (0.35 + 0.8 * saturate((px.y - oc.y) / (0.25 * u) + 0.5)), smoothstep(0.5, -0.5, od - orR - 0.055 * u));
    float3 orbCol = lerp(float3(0.06, 0.06, 0.1), lerp(curCol, white, 0.15 + 0.55 * saturate(1.0 - od / orR)), lit) * (0.65 + 0.35 * level + 0.35 * beat);
    orbCol += lit * lerp(curCol, white, 0.5) * 0.5 * smoothstep(0.6, 1.0, od / orR) * saturate((oc.y - px.y) / (0.12 * u) + 0.3);
    orbCol += white * 0.75 * smoothstep(0.06 * u, 0.02 * u, length(px - oc - float2(-0.06, 0.07) * u));
    layer(acc, cover, orbCol, smoothstep(0.5, -0.5, od - orR));

    // The front: a white-hot slanted edge, a flare that leaks past the frame and a lens streak that stretches on the beat.
    float fd = abs(s - head);
    layer(acc, cover, lerp(segCol, white, 0.5), exp(-length(float2(px.x - head, px.y - 0.5 * u)) / (0.3 * u)) * (0.45 + 0.4 * beat));
    layer(acc, cover, white, exp(-fd / (0.035 * u)) * inCh);
    layer(acc, cover, lerp(segCol, white, 0.4), exp(-fd / (0.03 * u)) * exp(-abs(y - 0.5) / (0.3 + 0.35 * beat)) * (0.6 + 0.4 * beat));
    float streak = exp(-abs(px.y - 0.5 * u) / 1.2) * exp(-abs(px.x - head) / (u * (0.6 + 2.4 * beat)));
    layer(acc, cover, lerp(segCol, white, 0.6), streak * (0.5 + 0.5 * beat));

    // Embers drift back from the front and fall.
    float cw = 0.28 * u, ci = floor(px.x / cw), h1 = hash1(ci), h2 = hash1(ci + 17.3);
    float life = frac(time * (0.9 + 0.6 * h2) + h1);
    float2 ep = float2((ci + 0.5) * cw - life * 0.3 * u, (0.5 + 0.3 * (h1 - 0.5) + 0.5 * life - 1.1 * life * life) * u);
    float ember = exp(-length(px - ep) / (0.04 * u)) * (1.0 - life) * step(0.45, h2) * exp(-max(head - ep.x, 0.0) / (1.6 * u)) * step(ep.x, head);
    layer(acc, cover, lerp(segCol, white, 0.6), ember * (0.9 + 0.5 * level));

    // On the beat a spray of hot sparks bursts from the front and arcs down under gravity.
    float t = (1.0 - beat) * 0.55, on = step(0.04, beat) * saturate(beat * 1.6);
    for (int i = 0; i < 9; i++)
    {
        float fi = i;
        float2 v = float2(-1.2 + 4.0 * hash1(fi + 1.0), 0.4 + 2.8 * hash1(fi + 2.0)) * u;
        float2 sa = px - float2(head, (0.35 + 0.3 * hash1(fi + 3.0)) * u) - v * t + float2(0.0, 5.5 * u) * t * t;
        float2 sb = -(v - float2(0.0, 11.0 * u) * t) * 0.04;           // a short streak along its flight
        float sd = length(sa - sb * saturate(dot(sa, sb) / max(dot(sb, sb), 0.001)));
        layer(acc, cover, colorC.rgb, on * exp(-sd / (0.06 * u)) * 0.5);
        layer(acc, cover, lerp(colorC.rgb, white, 0.7), on * smoothstep(0.03 * u + 0.6, 0.03 * u - 0.6, sd));
    }

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