Memphis

by MusicBar, visualizer

80s Memphis confetti along the bar: squiggles, zigzags, triangles, half circles and dot grids in bold pastels bounce and spin with the music, more of them the louder it gets, with new ones popping in on every beat.

4 downloads Download file, 5.1 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 dd36186c0ea0bbbad627e70cd023ef74477189c213c44c9e8a80e98dedcbdfd6

//! name: Memphis
//! author: MusicBar
//! kind: visualizer
//! description: 80s Memphis confetti along the bar: squiggles, zigzags, triangles, half circles and dot grids in bold pastels bounce and spin with the music, popping in on the beat, more of them the louder it gets.

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

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

float2 rot(float2 p, float a)
{
    float c = cos(a), s = sin(a);
    return float2(c * p.x + s * p.y, -s * p.x + c * p.y);
}

// Signed distance (pixels) to Memphis piece k of size r at p in its own frame:
// 0 squiggle, 1 zigzag, 2 triangle, 3 half circle, 4 ring, 5 dot grid.
float pieceD(float2 p, float k, float r)
{
    float squig = max(abs(p.y - 0.28 * r * sin(p.x / r * 6.0)) - 0.16 * r, abs(p.x) - r);
    float zz = max(abs(p.y - 0.3 * r * (abs(frac(p.x / (0.55 * r)) - 0.5) * 4.0 - 1.0)) - 0.15 * r, abs(p.x) - r);
    float2 t = float2(abs(p.x) - 0.95 * r, p.y + 0.95 * r / 1.732);
    t = (t.x + 1.732 * t.y > 0.0) ? float2(t.x - 1.732 * t.y, -1.732 * t.x - t.y) * 0.5 : t;
    t.x -= clamp(t.x, -1.9 * r, 0.0);
    float tri = -length(t) * sign(t.y);
    float half0 = max(length(p + float2(0.0, 0.35 * r)) - 0.95 * r, -(p.y + 0.35 * r));
    float ring = abs(length(p) - 0.68 * r) - 0.25 * r;
    float2 g = p - clamp(round(p / (0.62 * r)), -1.0, 1.0) * 0.62 * r;
    float grid = length(g) - 0.17 * r;
    return k < 0.5 ? squig : (k < 1.5 ? zz : (k < 2.5 ? tri : (k < 3.5 ? half0 : (k < 4.5 ? ring : grid))));
}

// One piece of confetti per cell of width cw on a slowly drifting grid: every few seconds the cell swaps its
// piece, popping the old one out and a new one in. It shows when the song is loud enough (or on a beat),
// hops with its part of the spectrum, spins, and casts a hard black offset shadow.
void piece(inout float3 acc, inout float cover, float2 px, float cw, float r, float sd, float base, float spread, float kinds, float shift)
{
    float u = size.y;
    float ci = floor((px.x + shift) / cw);
    float tt = time / 3.1 + hash2(float2(ci, sd + 5.0)) * 7.0;
    float win = floor(tt);
    float life = smoothstep(0.0, 0.05, frac(tt)) * smoothstep(1.0, 0.93, frac(tt));
    float h = hash2(float2(ci, sd + win * 3.1));
    float h2 = hash2(float2(ci + win * 1.7, sd + 1.0));
    float h3 = hash2(float2(ci, sd + 2.0 + win));
    float cx = (ci + 0.5 + 0.2 * (h2 - 0.5)) * cw - shift;
    float s = spectrum(saturate(abs(cx / size.x - 0.5) * 2.0));
    float pop = saturate((base + 0.45 * level + 0.35 * beat - h) * 7.0) * life;
    pop *= 1.0 + 0.25 * sin(pop * 3.1416);                   // a little overshoot as it pops in
    float hop = abs(sin(time * (2.6 + 2.0 * h3) + h * 20.0)) * (0.03 + 0.09 * s) * u + 0.08 * u * beat * step(0.35, h3);
    float2 c = float2(cx, u * (0.47 + spread * (h3 - 0.5)) + hop);
    float ang = h * 6.2832 + time * (h2 - 0.5) * 3.0 + beat * 0.9 * (h3 - 0.5);
    float sc = max(pop * (1.0 + 0.15 * beat), 0.001);
    float k = floor(frac(h * 7.31) * kinds);
    k = kinds < 3.5 ? (k < 0.5 ? 2.0 : (k < 1.5 ? 4.0 : 1.0)) : k;   // small confetti: triangles, rings, zigzags
    float aa = 0.5;

    float d = pieceD(rot(px - c, ang) / sc, k, r) * sc;
    float ds = pieceD(rot(px - c + float2(-0.09, 0.09) * r * sc, ang) / sc, k, r) * sc;
    float pick = frac(h2 * 3.7);
    float3 col = pick < 0.34 ? colorA.rgb : (pick < 0.67 ? colorB.rgb : colorC.rgb);
    col = lerp(col, float3(1, 1, 1), 0.12);
    col = k > 4.5 ? float3(0.98, 0.97, 0.95) : col;             // dot grids are white with black rims
    float filled = step(1.5, k);
    float on = step(0.01, pop);

    // Shadow, fill, black rim on the solid pieces, then the black pattern inside them.
    float3 ink = float3(0.05, 0.05, 0.07);
    layer(acc, cover, ink, smoothstep(aa, -aa, ds) * on * 0.9);
    layer(acc, cover, col, smoothstep(aa, -aa, d) * on);
    float rim = max(0.7, 0.07 * r * sc);
    layer(acc, cover, ink, smoothstep(rim + aa, rim - aa, abs(d + rim * 0.5)) * filled * on);
    float2 lp = rot(px - c, ang) / sc;
    float dots = length(frac(lp / (0.3 * r)) - 0.5) * 0.3 * r - 0.06 * r;
    float stripes = abs(frac(lp.y / (0.3 * r)) - 0.5) * 0.3 * r - 0.035 * r;
    float pat = k < 1.5 ? 99.0 : (k < 2.5 ? dots : (k < 3.5 ? stripes : 99.0));
    layer(acc, cover, ink, smoothstep(aa, -aa, pat * sc) * smoothstep(aa, -aa, d + rim) * on);
}

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float u = size.y;
    float2 px = float2(uv.x * size.x, (1.0 - uv.y) * u);     // pixels, y up the screen so the pieces hop upward

    float3 acc = float3(0, 0, 0);
    float cover = 0;

    // Small confetti behind, the big pieces in front, on two offset grids so they overlap like a scattered layout.
    piece(acc, cover, px, 0.62 * u, 0.16 * u, 11.0, 0.62, 0.6, 3.0, time * 0.45 * u + 0.31 * u);
    piece(acc, cover, px, 1.1 * u, 0.34 * u, 3.0, 0.5, 0.16, 6.0, time * 0.25 * u);

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