Pop Art

của MusicBar, visualizer

Khung truyện tranh thập niên 60: sóng chấm bi nhấp nhô theo phổ nhạc dưới viền đen đậm, vệt tốc độ lướt qua, tới nhịp là mấy bong bóng nổ răng cưa bung ra.

2 lượt tải Tải file, 6.1 KB
Cách cài, mã SHA-256 và mã nguồn

Bấm Áp dụng: MusicBar tự tải về, kiểm tra mã SHA-256 rồi mặc lên taskbar; có rồi thì mặc luôn. Cần MusicBar 1.8 trở lên.

SHA-256 ff413d27c6e3bc8dedd53bd96332d0c71c3af8842b10b920a53e5fad6f05bec9

//! name: Pop Art
//! author: MusicBar
//! kind: visualizer
//! description: A 60s comic panel: halftone waves ride the spectrum under bold black outlines, speed lines streak past and jagged starbursts explode 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);
}

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

// Ben-Day dots on a 45 degree grid: distance in pixels to the nearest dot, dots grow with the ink amount f.
float benday(float2 px, float cell, float f)
{
    float2 r = float2(px.x + px.y, px.y - px.x) * 0.7071 / cell;
    return (length(frac(r) - 0.5) - 0.74 * sqrt(saturate(f))) * cell;
}

// A jagged comic starburst: spikes of random length around a ring, an even count so the seam stays clean.
float burstD(float2 d, float R, float sd)
{
    float a = atan2(d.y, d.x) / 6.2832 * 14.0;
    float amp = 0.45 + 0.55 * hash2(float2(floor(a), sd));
    float tri = 1.0 - abs(2.0 * frac(a) - 1.0);
    return (length(d) - R * (0.55 + 0.45 * amp * tri)) * 0.55;
}

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 x = px.x / u;
    float lw = max(1.3, 0.05 * u);                            // the bold black outline
    float3 ink = float3(0.04, 0.04, 0.05);
    float3 paper = float3(1.0, 0.98, 0.92);
    float mirror = abs(frac(x / 10.0) - 0.5) * 2.0;          // the spectrum, mirrored every ten bar heights
    float sBass = (spectrum(saturate(mirror - 0.03)) + spectrum(mirror) + spectrum(saturate(mirror + 0.03))) / 3.0;
    float sHigh = (spectrum(saturate(0.97 - mirror)) + spectrum(saturate(1.03 - mirror))) * 0.5;

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

    // Back wave: fine blue Ben-Day dots under a black contour, riding the treble.
    float h2 = u * (0.26 + 0.5 * sHigh + 0.08 * sin(x * 1.1 + time * 1.4));
    float t2 = saturate((h2 - px.y) / h2);
    float in2 = smoothstep(0.5, -0.5, px.y - h2);
    layer(acc, cover, colorB.rgb, in2 * smoothstep(0.5, -0.5, benday(px + float2(0.06 * u, 0.0), 0.12 * u, 0.04 + 0.3 * t2)));
    layer(acc, cover, ink, smoothstep(lw * 0.5 + 0.5, lw * 0.5 - 0.5, abs(px.y - h2)));

    // Front wave: red dots riding the bass, growing with depth and on the beat, a paper-white sheen under its contour.
    float h1 = u * (0.12 + 0.45 * sBass * (0.85 + 0.35 * beat) + (0.05 + 0.07 * level) * sin(x * 1.3 - time * 2.2));
    float t1 = saturate((h1 - px.y) / h1);
    float in1 = smoothstep(0.5, -0.5, px.y - h1);
    layer(acc, cover, colorA.rgb, in1 * smoothstep(0.5, -0.5, benday(px, 0.13 * u, 0.07 + 0.42 * t1 + 0.1 * beat)));
    layer(acc, cover, paper, in1 * smoothstep(lw * 0.4 + 0.5, lw * 0.4 - 0.5, abs(h1 - px.y - lw * 1.4)) * 0.85);
    layer(acc, cover, ink, smoothstep(lw * 0.5 + 0.5, lw * 0.5 - 0.5, abs(px.y - h1)));

    // Speed lines streaking left, inked edge and white core, more of them when the song is loud.
    float rowH = 0.085 * u;
    float row = floor(px.y / rowH);
    float rh = hash2(float2(row, 7.0));
    float lx = x + time * (5.0 + 7.0 * rh) + rh * 50.0;
    float seg = floor(lx / 2.2);
    float len = 0.5 + 1.2 * hash2(float2(seg, row + 3.0));
    float lf = saturate(frac(lx / 2.2) * 2.2 / len);
    float thick = 0.024 * u * sin(lf * 3.1416) + 0.3;
    float onLine = step(hash2(float2(seg, row)), 0.18 + 0.4 * level) * step(frac(lx / 2.2) * 2.2, len) * step(0.42 * u, px.y) * step(px.y, 0.94 * u);
    float dl = abs(px.y - (row + 0.5) * rowH);
    layer(acc, cover, ink, onLine * smoothstep(thick + 1.0, thick, dl) * 0.9);
    layer(acc, cover, paper, onLine * smoothstep(thick * 0.5 + 0.5, thick * 0.5 - 0.5, dl));

    // Starbursts: each slot pops one in for a while, and the beat inflates them and throws extra ones out.
    float slot = floor(x / 3.3);
    float h0 = hash2(float2(slot, 1.0));
    float tt = time / 1.7 + h0 * 5.0;
    float win = floor(tt);
    float f = frac(tt);
    float hv = hash2(float2(slot, win));
    float shown = step(hv, 0.42 + 0.3 * level) * smoothstep(0.0, 0.05, f) * (1.0 + 0.3 * exp(-f * 25.0)) * smoothstep(1.0, 0.93, f);
    float extra = step(0.42 + 0.3 * level, hv) * smoothstep(0.0, 0.4, beat);
    float sc = max(shown, extra) * (1.0 + 0.25 * beat);
    float2 bc = float2((slot + 0.5 + 0.35 * (h0 - 0.5)) * 3.3 * u, u * (0.52 + 0.1 * (hash2(float2(slot, win + 9.0)) - 0.5)));
    float2 d = px - bc;
    float ra = hv * 6.0 + 0.06 * sin(time * 3.0 + h0 * 9.0);
    d = float2(cos(ra) * d.x + sin(ra) * d.y, -sin(ra) * d.x + cos(ra) * d.y);
    float R = 0.43 * u * sc;
    float outer = burstD(d, R, win + slot * 7.0);
    float inner = burstD(d, R * 0.6, win + slot * 7.0 + 50.0);
    float vis = step(0.02, sc);

    // Action rays flung out of the burst on the beat.
    float ray = atan2(d.y, d.x) / 6.2832 * 28.0;
    float rayOn = step(hash2(float2(floor(ray), slot + win)), 0.5) * vis * beat;
    float rd = length(d);
    float rayW = (0.5 - abs(frac(ray) - 0.5)) * 6.2832 / 28.0 * rd;
    float rayLen = step(R * 1.05, rd) * step(rd, R * (1.35 + 0.5 * beat));
    layer(acc, cover, ink, rayOn * rayLen * smoothstep(lw * 0.9 + 0.5, lw * 0.9 - 0.5, rayW));
    layer(acc, cover, paper, rayOn * rayLen * smoothstep(lw * 0.4 + 0.5, lw * 0.4 - 0.5, rayW));

    // The burst: black outline, yellow with orange dots, a red core and a white flash at its heart.
    float3 yel = lerp(colorC.rgb, lerp(colorC.rgb, colorA.rgb, 0.45), step(benday(px, 0.11 * u, 0.25), 0.0));
    float3 bcol = lerp(yel, colorA.rgb, step(inner, 0.0));
    bcol = lerp(bcol, paper, smoothstep(R * 0.22, R * 0.08, rd) * (0.6 + 0.4 * beat));
    layer(acc, cover, ink, vis * smoothstep(lw + 0.5, lw - 0.5, outer));
    layer(acc, cover, bcol, vis * smoothstep(0.5, -0.5, outer));
    layer(acc, cover, ink, vis * smoothstep(lw * 0.45 + 0.5, lw * 0.45 - 0.5, abs(inner)) * step(outer, 0.0));

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