Topo Lines

của MusicBar, visualizer

Đường đồng mức như bản đồ địa hình trôi dọc thanh, đồi núi nhô cao theo phổ nhạc, cứ năm đường lại có một đường đậm, trên đỉnh có chấm sáng phập phồng theo nhịp.

19 lượt tải Tải file, 4.7 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 fd3b8ca26433b393c78ab50d119a971804cc8d652f3bf0a18bd212d184b9671b

//! name: Topo Lines
//! author: MusicBar
//! kind: visualizer
//! description: Topographic contour lines drift along the bar like a moving map, the hills swelling with the spectrum, every fifth line drawn bolder and the summits marked with dots that pulse on the beat.

float hash1(float n) { n = frac(n * 0.1031); n *= n + 33.33; n *= n + n; return frac(n); }
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);
}

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float u = size.y;
    float2 px = uv * size;
    float drift = time * 0.12;                                  // the map slides slowly along the bar
    float2 p = float2(px.x / u + drift, px.y / u);              // map position in bar heights
    float W = 1.7;                                              // one hill per cell this wide
    float k0 = floor(p.x / W);

    // Rolling ground from soft noise, then a hill per cell whose height follows the spectrum under it.
    float h = 0.45 * vnoise(p * 0.8 + float2(0.0, time * 0.04)) + 0.2 * vnoise(p * 1.9 + 7.0);
    float2 pw = p + 0.18 * float2(vnoise(p * 1.3 + 3.0), vnoise(p * 1.3 + 9.0)) - 0.09;   // ridges wander, not perfect domes
    float peakD = 1e4, peakA = 0;
    for (int i = -1; i <= 1; i++)
    {
        float k = k0 + i;
        float2 c = float2((k + 0.25 + 0.5 * hash1(k * 3.1 + 1.0)) * W, 0.25 + 0.5 * hash1(k * 5.7 + 2.0));
        float rad = 0.42 + 0.3 * hash1(k * 7.3 + 3.0);
        float sx = abs((c.x - drift) * u / size.x - 0.5) * 2.0;
        float amp = (0.35 + 0.5 * hash1(k * 9.1 + 4.0)) * (0.25 + 1.5 * spectrum(saturate(sx)));
        float2 dd = (pw - c) / (rad * float2(1.5, 1.0));
        h += amp * exp(-dot(dd, dd));
        float dp = length(pw - c) * u;
        float big = step(0.62, hash1(k * 9.1 + 4.0) + 0.3 * step(0.5, hash1(k * 2.3 + 6.0)));
        peakA = dp < peakD ? big : peakA;
        peakD = min(peakD, dp);
    }

    // Contours: a line at every step of height, every fifth one bolder.
    float N = 11.0;
    float f = h * N;
    float fw = max(fwidth(f), 0.0001);
    float dl = abs(frac(f + 0.5) - 0.5) / fw;                   // pixels to the nearest contour
    float idx = floor(f + 0.5);
    float major = step(abs(frac(idx / 5.0 + 0.1) - 0.1), 0.01);
    float w = max(0.45, u / 110.0) * lerp(1.0, 2.0, major);

    // Elevation tints: low ground in the second color, slopes in the main color, summits in the accent.
    float e = saturate(h / 1.6);
    float3 c = lerp(colorB.rgb, colorA.rgb, smoothstep(0.15, 0.55, e));
    c = lerp(c, colorC.rgb, smoothstep(0.6, 0.95, e));

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

    // A faint survey grid, and a soft wash on the high ground.
    float2 gq = abs(frac(float2(p.x / 1.5, p.y * 2.0 + 0.5)) - 0.5) * float2(1.5, 0.5) * u;
    float grid = smoothstep(0.9, 0.2, min(gq.x, gq.y)) * step(0.5, frac((p.x + p.y) * 6.0));
    layer(acc, cover, lerp(colorB.rgb, float3(1, 1, 1), 0.3), grid * 0.12);
    layer(acc, cover, c, smoothstep(0.35, 1.2, h) * 0.1 * (0.7 + 0.3 * level));

    // The lines: a faint dark edge so they hold on a light taskbar, a glow, then the line itself.
    float lineA = smoothstep(w + 0.5, w - 0.5, dl);
    layer(acc, cover, float3(0.02, 0.02, 0.05), smoothstep(w + 1.5, w + 0.5, dl) * (1.0 - lineA) * (0.12 + 0.2 * major));
    layer(acc, cover, c, exp(-max(dl - w, 0.0) / (1.2 + 1.2 * major)) * (0.1 + 0.15 * major) * (0.7 + 0.5 * level));
    layer(acc, cover, lerp(c, float3(1, 1, 1), 0.15 * major + 0.2 * beat * major), lineA * lerp(0.75, 1.0, major));

    // Summit markers on the bigger hills: a dot with a dark rim, swelling and ringing out on the beat.
    float pr = 0.06 * u * (1.0 + 0.6 * beat);
    float ring = smoothstep(1.2, 0.0, abs(peakD - pr - (1.0 - beat) * 0.35 * u)) * beat;
    layer(acc, cover, colorC.rgb, ring * peakA * 0.9);
    layer(acc, cover, colorC.rgb, exp(-max(peakD - pr, 0.0) / (0.06 * u)) * peakA * (0.35 + 0.5 * beat));
    layer(acc, cover, float3(0.05, 0.03, 0.02), smoothstep(0.5, -0.5, peakD - pr - 1.2) * peakA * 0.8);
    layer(acc, cover, lerp(colorC.rgb, float3(1, 1, 1), 0.35 + 0.4 * beat), smoothstep(0.5, -0.5, peakD - pr) * peakA);

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