Saigon Rush

by MusicBar, visualizer

Saigon rush hour: lanes of little scooters with helmeted riders, passengers, towering loads and even a potted apricot blossom tree stream under warm street lights, surging when the song gets loud and honking with a flash on every beat.

21 downloads Download file, 11.3 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 08c353280d21804266b8d06e6939b1246467798aef1e18895f69d2379d406225

//! name: Saigon Rush
//! author: MusicBar
//! kind: visualizer
//! description: Rush hour in Saigon: lanes of little scooters with helmeted riders, passengers and towering loads stream under warm street lights, surging when the song gets loud and honking with a flash on every beat.

float hash1(float n) { return frac(sin(n * 127.1 + 311.7) * 43758.5453); }
float ellipse(float2 p, float2 r) { float k0 = length(p / r); return k0 * (k0 - 1.0) / max(length(p / (r * r)), 0.0001); }
float sdSeg(float2 p, float2 a, float2 b) { float2 pa = p - a, ba = b - a; return length(pa - ba * saturate(dot(pa, ba) / dot(ba, ba))); }
float boxD(float2 p, float2 b) { float2 d = abs(p) - b; return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0); }

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

float3 pick(float k)
{
    return k < 0.25 ? colorA.rgb : (k < 0.5 ? colorB.rgb : (k < 0.75 ? colorC.rgb : float3(0.95, 0.95, 0.92)));
}

// One scooter and its rider in the scooter's own frame (1 = its height, ground at y = 0, heading right).
// h picks the look and the load: alone, a passenger, a tower of boxes, or a delivery box.
void scooter(inout float3 acc, inout float cover, float2 p, float h, float aa, float lean, float honk, float spin)
{
    float kind = frac(h * 7.0);
    float3 paint0 = lerp(pick(frac(h * 3.0)), float3(0.85, 0.15, 0.15), step(0.8, frac(h * 11.0)));
    float3 helm = pick(frac(h * 5.0 + 0.3)), shirt = lerp(float3(0.25, 0.3, 0.45), pick(frac(h * 13.0)), 0.55);

    // Headlight beam ahead, tail light glow behind, and a soft shadow on the road.
    float bx = p.x - 0.36;
    float beam = step(0.0, bx) * exp(-abs(p.y - 0.4 + 0.18 * bx) / (0.03 + 0.2 * bx)) * exp(-bx / 0.45);
    layer(acc, cover, float3(1.0, 0.93, 0.75), beam * (0.3 + 0.2 * level + 0.6 * honk));
    layer(acc, cover, float3(1.0, 0.1, 0.12), exp(-length((p - float2(-0.44, 0.28)) / float2(1.6, 1.0)) / 0.05) * 0.6);
    layer(acc, cover, float3(0, 0, 0), exp(-abs(p.y) / 0.03) * smoothstep(0.5, 0.3, abs(p.x + 0.03)) * 0.5);

    // The load behind the rider: a tower of strapped boxes, or one square delivery box.
    float2 sq = p - float2(-0.43, 0.6);
    float dStack = boxD(sq, float2(0.15, 0.27)) - 0.01;
    float row = floor(sq.y / 0.135 + 2.0);
    float3 boxC = float3(0.72, 0.52, 0.3) * (0.8 + 0.25 * hash1(row + h * 50.0)) * (0.85 + 0.15 * step(0.08, abs(frac(sq.y / 0.135) - 0.5) * 2.0));
    boxC = lerp(boxC, float3(0.95, 0.9, 0.8), smoothstep(0.02, 0.0, abs(sq.x - 0.02)) * 0.7);
    float isStack = step(0.5, kind) * step(kind, 0.75);
    layer(acc, cover, float3(0.08, 0.05, 0.03), smoothstep(aa, -aa, dStack - aa * 1.3) * isStack);
    layer(acc, cover, boxC, smoothstep(aa, -aa, dStack) * isStack);
    float dBox = boxD(p - float2(-0.36, 0.48), float2(0.12, 0.12)) - 0.015;
    float isBox = step(0.75, kind) * step(kind, 0.89), isTree = step(0.89, kind);

    // Or, as at Tet, a potted yellow apricot blossom tree riding home on the back.
    float2 tq = p - float2(-0.5, 0.86);
    float dCan = min(min(length(tq) - 0.15, length(tq + float2(0.13, 0.07)) - 0.11), length(tq - float2(0.12, -0.06)) - 0.11) - 0.015 * sin(tq.x * 70.0) * sin(tq.y * 60.0);
    float dTrunk = min(min(sdSeg(p, float2(-0.4, 0.44), float2(-0.47, 0.76)), sdSeg(p, float2(-0.45, 0.62), float2(-0.62, 0.8))) - 0.018, boxD(p - float2(-0.4, 0.42), float2(0.07, 0.05)));
    float bloom = step(0.4, hash1(dot(floor(tq * 26.0), float2(1.0, 57.0)) + h)) * (0.8 + 0.2 * sin(time * 3.0 + tq.x * 50.0));
    layer(acc, cover, float3(0.06, 0.04, 0.02), smoothstep(aa, -aa, min(dCan, dTrunk) - aa * 1.3) * isTree);
    layer(acc, cover, lerp(float3(0.42, 0.24, 0.12), float3(0.75, 0.15, 0.1), step(p.y, 0.47)), smoothstep(aa, -aa, dTrunk) * isTree);
    layer(acc, cover, lerp(float3(0.35, 0.3, 0.1), lerp(float3(1.0, 0.82, 0.12), colorA.rgb, 0.15) * (0.8 + 0.3 * saturate(tq.y / 0.2 + 0.5)), saturate(bloom + 0.35)), smoothstep(aa, -aa, dCan) * isTree);
    layer(acc, cover, float3(0.05, 0.05, 0.05), smoothstep(aa, -aa, dBox - aa * 1.3) * isBox);
    layer(acc, cover, lerp(colorC.rgb, float3(1, 1, 1), 0.15) * (0.75 + 0.35 * saturate((p.y - 0.36) / 0.24)), smoothstep(aa, -aa, dBox) * isBox);

    // A passenger riding pillion, sitting a little higher.
    float2 pp = p - float2(-0.2, 0.0);
    float dPas = min(sdSeg(pp, float2(-0.08, 0.4), float2(-0.04 + lean * 0.5, 0.66)) - 0.065, length(pp - float2(-0.01 + lean * 0.5, 0.79)) - 0.1);
    float isPas = step(0.25, kind) * step(kind, 0.5);
    float3 pasC = lerp(lerp(float3(0.85, 0.3, 0.4), pick(frac(h * 17.0)), 0.5), pick(frac(h * 19.0 + 0.5)), step(0.71, pp.y));
    layer(acc, cover, float3(0.04, 0.04, 0.05), smoothstep(aa, -aa, dPas - aa * 1.3) * isPas);
    layer(acc, cover, pasC * 0.8, smoothstep(aa, -aa, dPas) * isPas);

    // Wheels with spinning spokes.
    float2 wq = p - float2(p.x < 0.0 ? -0.29 : 0.32, 0.115);
    float wr = length(wq);
    float spokes = 0.6 + 0.4 * step(0.0, sin(atan2(wq.y, wq.x + 0.0001) * 3.0 + spin));
    layer(acc, cover, float3(0.03, 0.03, 0.04), smoothstep(aa, -aa, wr - 0.115 - aa * 1.3));
    layer(acc, cover, lerp(float3(0.1, 0.1, 0.11), float3(0.75, 0.77, 0.8) * spokes, smoothstep(0.072, 0.062, wr)), smoothstep(aa, -aa, wr - 0.115));

    // The scooter: rear cowl, floorboard, leg shield, fender and handlebars; a dark seat on top.
    float dBody = ellipse(p - float2(-0.2, 0.25), float2(0.25, 0.1));
    dBody = min(dBody, boxD(p - float2(0.06, 0.16), float2(0.16, 0.025)));
    dBody = min(dBody, sdSeg(p, float2(0.24, 0.17), float2(0.3, 0.47)) - 0.05);
    dBody = min(dBody, max(ellipse(p - float2(0.32, 0.13), float2(0.13, 0.08)), 0.13 - p.y));
    float dSeat = ellipse(p - float2(-0.19, 0.345), float2(0.17, 0.04));
    float3 bodyC = paint0 * (0.55 + 0.6 * saturate((p.y - 0.12) / 0.25)) + 0.3 * exp(-abs(p.y - 0.3) / 0.02) * step(p.x, 0.0);
    layer(acc, cover, float3(0.04, 0.04, 0.05), smoothstep(aa, -aa, min(dBody, dSeat) - aa * 1.3));
    layer(acc, cover, bodyC, smoothstep(aa, -aa, dBody));
    layer(acc, cover, float3(0.1, 0.09, 0.1), smoothstep(aa, -aa, dSeat));

    // The rider: legs to the floorboard, a body leaning in with the speed, an arm to the bars, a helmet with a visor.
    float2 hip = float2(-0.12, 0.39), sh = float2(-0.06 + lean, 0.66), hd = float2(-0.02 + lean * 1.2, 0.8);
    float dLeg = min(sdSeg(p, hip, float2(0.1, 0.43)), sdSeg(p, float2(0.1, 0.43), float2(0.13, 0.19))) - 0.045;
    float dTorso = sdSeg(p, hip, sh) - 0.075;
    float dArm = sdSeg(p, sh, float2(0.27, 0.5)) - 0.032;
    float dHelm = max(length(p - hd) - 0.11, hd.y - 0.035 - p.y);
    float dFace = length(p - hd - float2(0.03, -0.045)) - 0.065;
    float dRider = min(min(min(dLeg, dTorso), dArm), min(dHelm, dFace));
    layer(acc, cover, float3(0.04, 0.04, 0.05), smoothstep(aa, -aa, dRider - aa * 1.3));
    layer(acc, cover, float3(0.12, 0.13, 0.17), smoothstep(aa, -aa, dLeg));
    layer(acc, cover, shirt * (0.7 + 0.4 * saturate((p.x - sh.x + 0.08) / 0.15)), smoothstep(aa, -aa, min(dTorso, dArm)));
    layer(acc, cover, float3(0.85, 0.65, 0.5), smoothstep(aa, -aa, dFace));
    float visor = smoothstep(0.02, 0.0, abs(p.y - hd.y + 0.005) - 0.025) * step(hd.x + 0.04, p.x);
    layer(acc, cover, lerp(helm * (0.65 + 0.5 * saturate((p.y - hd.y + 0.05) / 0.12)), float3(0.1, 0.12, 0.15), visor * 0.8), smoothstep(aa, -aa, dHelm));

    // The lamps, then the honk: a flash at the headlight and sound rings spreading ahead.
    layer(acc, cover, float3(1.0, 0.97, 0.85), smoothstep(aa, -aa, ellipse(p - float2(0.34, 0.43), float2(0.03, 0.025))) + honk * exp(-length(p - float2(0.36, 0.43)) / 0.08));
    layer(acc, cover, float3(1.0, 0.2, 0.15), smoothstep(aa, -aa, ellipse(p - float2(-0.45, 0.28), float2(0.02, 0.025))));
    float2 hq = p - float2(0.4, 0.62);
    float ring = abs(frac(length(hq) / 0.07 - (1.0 - honk) * 2.0) - 0.5) * 0.07;
    layer(acc, cover, lerp(pick(frac(h * 23.0)), float3(1, 1, 1), 0.4), smoothstep(aa * 1.2, 0.0, ring - 0.006) * step(abs(atan2(hq.y, hq.x)), 0.6) * step(length(hq), 0.25) * honk);
}

// One lane of traffic: scooters spaced in cells (some left empty), each weaving a little and bouncing on the road.
// A pixel draws the scooter of its own cell and the nearer neighbor. A loud song pushes the whole stream forward.
void lane(inout float3 acc, inout float cover, float2 px, float ground, float S, float speed, float seed, float gaps, float dim)
{
    float x = (px.x - (time + 0.35 * level) * speed * size.y) / S;
    float c = floor(x / 1.3);
    float n = c + (frac(x / 1.3) < 0.5 ? -1.0 : 1.0);
    float ha = hash1(n * 3.7 + seed), hb = hash1(c * 3.7 + seed), hk = floor(time * 2.0) + seed;
    float2 pa = float2(x - (n + 0.5 + 0.18 * sin(time * 0.6 + ha * 20.0)) * 1.3, (px.y - ground) / S - 0.01 * sin(time * 8.0 + ha * 30.0) + 20.0 * step(frac(ha * 31.0), gaps));
    float2 pb = float2(x - (c + 0.5 + 0.18 * sin(time * 0.6 + hb * 20.0)) * 1.3, (px.y - ground) / S - 0.01 * sin(time * 8.0 + hb * 30.0) + 20.0 * step(frac(hb * 31.0), gaps));
    float3 a2 = float3(0, 0, 0);
    float c2 = 0;
    float spin = time * 22.0;
    scooter(a2, c2, pa, ha, 1.0 / S, 0.05 * level, beat * step(0.55, hash1(n + hk)), spin);
    scooter(a2, c2, pb, hb, 1.0 / S, 0.05 * level, beat * step(0.55, hash1(c + hk)), spin);
    layer(acc, cover, a2 / max(c2, 0.001) * dim, c2 * (0.5 + 0.5 * dim));
}

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 traffic always rides upright
    float aa = 1.0 / u;
    float3 acc = float3(0, 0, 0);
    float cover = 0;

    // Street lamps: a warm sodium head on a curved arm and a pool of light on the road below.
    float lw = 4.3 * u;
    float lx = (floor(px.x / lw) + 0.5) * lw;
    float2 lq = (px - float2(lx, 0.0)) / u;
    layer(acc, cover, lerp(float3(1.0, 0.62, 0.25), colorA.rgb, 0.2), exp(-length((lq - float2(0.25, 0.5)) / float2(0.9, 1.3)) / 0.35) * 0.22);
    float dLamp = min(abs(lq.x) - 0.022, length(lq - float2(0.14, 0.9)) - 0.05);
    dLamp = min(max(dLamp, lq.y - 0.92), max(abs(length(lq - float2(0.12, 0.8)) - 0.12) - 0.015, -lq.y + 0.8));
    layer(acc, cover, float3(0.32, 0.33, 0.36), smoothstep(aa, -aa, dLamp));
    layer(acc, cover, float3(1.0, 0.8, 0.45), smoothstep(aa, -aa, ellipse(lq - float2(0.26, 0.88), float2(0.08, 0.03))) + exp(-length(lq - float2(0.26, 0.87)) / 0.06) * 0.6);

    // Tangled power lines sagging from pole to pole, swaying a little.
    float wf = frac(px.x / lw), sag = 4.0 * wf * (1.0 - wf);
    float wires = smoothstep(1.2, 0.2, abs(px.y - u * (0.97 - 0.1 * sag + 0.01 * sin(time * 1.3))));
    wires = max(wires, smoothstep(1.2, 0.2, abs(px.y - u * (0.93 - 0.14 * sag + 0.015 * sin(time * 1.1 + 1.0)))));
    wires = max(wires, smoothstep(1.2, 0.2, abs(px.y - u * (0.9 - 0.07 * sag - 0.05 * sin(wf * 9.0) * sag))));
    layer(acc, cover, float3(0.45, 0.4, 0.35), wires * 0.7);

    // The far lane, smaller, slower and dimmer; a dashed lane line; then the near lane, bigger and faster, in front.
    lane(acc, cover, px, 0.4 * u, 0.46 * u, 1.0, 1.0, 0.32, 0.68);
    layer(acc, cover, float3(0.9, 0.85, 0.7), step(0.5, frac(px.x / (0.8 * u))) * smoothstep(1.0, 0.0, abs(px.y - 0.37 * u) - 0.01 * u) * 0.35);
    lane(acc, cover, px, 0.02 * u, 0.72 * u, 1.6, 9.0, 0.22, 1.0);

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