Great Wave

của MusicBar, thanh tiến trình

Con sóng lừng kiểu tranh khắc gỗ Nhật cuộn tới chỗ đang phát, bọt trắng xòe ra như móng vuốt, phía trước là ngọn núi xa bé tí, sóng phía sau dập dềnh theo tiếng bass, tới nhịp là bọt nước tung lên.

1 lượt tải Tải file, 8.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 062c68d36daf225e9d16707d059292773c1ebcd1fe7f8cc7bbcd737e3e6e3b7d

//! name: Great Wave
//! author: MusicBar
//! kind: progress
//! description: A ukiyo-e great wave curls at the playhead with clawed cream foam over a tiny distant mountain, while a calmer woodblock swell rolls behind it and heaves with the bass.

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

// One swell, k the place within it: a slow back, a steep front and a sharp woodblock crest.
float swell(float k)
{
    return pow(saturate(1.0 - abs(2.0 * pow(k, 1.6) - 1.0)), 2.0);
}

// Height of the near sea at x (bar heights from the playhead): the crest's hill, gentle behind and steep in
// front, or the rolling swell behind it, whichever is higher; a calm line ahead.
float seaY(float x, float xo, float amp, float lift)
{
    float sw = (0.12 + amp * swell(frac((x + xo) / 1.05 - time * 0.23)) * smoothstep(0.1, -0.9, x)) * step(x, 0.0);
    float w = x < -0.3 ? 0.95 : 0.27;
    float calm = 0.05 + 0.008 * sin(x * 13.0 - time * 1.4) * smoothstep(0.3, 0.8, x);
    float hill = lerp(0.15, calm, smoothstep(0.1, 0.55, x)) + (0.42 + lift) * exp(-pow((x + 0.3) / w, 2.0));
    return max(sw, hill);
}

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 head = progress * size.x;
    float2 q = float2(px.x - head, px.y) / u;                 // bar heights, the playhead at x = 0
    float aa = 1.0 / u;
    float lw = max(0.9 / u, 0.02);                            // the carved outline width
    float bass = spectrum(0.04);
    float lift = 0.03 * bass + 0.06 * beat;

    float3 ink = lerp(float3(0.04, 0.06, 0.13), colorA.rgb * 0.2, 0.3);
    float3 cream = lerp(float3(0.97, 0.93, 0.82), colorC.rgb, 0.25);
    float3 pale = lerp(colorA.rgb, colorB.rgb, 0.75);
    float grain = vnoise(px * float2(0.8, 0.3)) * 0.6 + vnoise(px * 0.45 + 7.0) * 0.4;

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

    // A tiny distant mountain ahead of the crest: a snow cap with a jagged edge over faded blue slopes.
    float2 m = q - float2(0.9, 0.04);
    float mx = max(abs(m.x) - 0.02, 0.0) / 0.34;
    float mY = 0.3 * pow(saturate(1.0 - mx), 1.7);
    float dM = (m.y - mY) / sqrt(1.0 + 2.3 * saturate(1.0 - mx));
    float snow = step(0.3 * (0.5 + 0.16 * abs(frac(m.x * 9.0) - 0.5)), m.y);
    float3 slope = lerp(lerp(colorB.rgb, float3(0.85, 0.85, 0.8), 0.35), colorA.rgb, 0.3);
    layer(acc, cover, lerp(slope, cream, snow) * (0.95 + 0.1 * grain), smoothstep(0.5 * aa, -0.5 * aa, dM) * 0.9);
    layer(acc, cover, ink, smoothstep(0.7 * aa + lw * 0.4, lw * 0.4 - 0.3 * aa, abs(dM)) * step(0.0, m.y) * 0.8);

    // The far swell: paler, smaller, drifting slower behind (parallax), a cream frill on each crest.
    float fk = frac((px.x / u) / 0.8 - time * 0.12 + 0.37);
    float fs = pow(0.5 + 0.5 * cos(6.2832 * (fk - 0.65)), 1.5);
    float fy = 0.15 + (0.1 + 0.06 * bass) * fs;
    float dF = (q.y - fy) * 0.8;
    float farZone = smoothstep(0.0, -0.9, q.x);
    float3 farC = lerp(lerp(colorA.rgb, pale, 0.55), pale, smoothstep(0.006, 0.0, abs(frac((fy - q.y) / 0.05) - 0.5) * 0.05 - 0.004));
    farC = lerp(farC, cream, smoothstep(0.03, 0.012, fy - q.y) * smoothstep(0.22, 0.05, abs(fk - 0.65)));
    layer(acc, cover, farC, smoothstep(0.5 * aa, -0.5 * aa, dF) * farZone * 0.75);
    layer(acc, cover, ink, smoothstep(lw * 0.5 + aa, lw * 0.5, abs(dF)) * farZone * 0.6);

    // The near sea: crest hill plus swell, with its outline distance taken from the slope.
    float amp = 0.16 + 0.12 * bass + 0.05 * beat;
    float xo = head / u;
    float S = seaY(q.x, xo, amp, lift);
    float dS = (seaY(q.x + 0.01, xo, amp, lift) - seaY(q.x - 0.01, xo, amp, lift)) / 0.02;
    float dSea = (q.y - S) / sqrt(1.0 + dS * dS);
    float depth = S - q.y;

    // Foam on each swell crest: a cream cap with small claws hooking forward off the steep front.
    float k = frac((q.x + xo) / 1.05 - time * 0.23);
    float swellZone = smoothstep(-0.3, -0.9, q.x);
    float capM = smoothstep(0.2, 0.04, abs(k - 0.62)) * swellZone;
    float tooth = frac((k - 0.6) * 1.05 / 0.06);
    float clawH = 0.055 * pow(tooth, 1.4) * step(0.6, k) * step(k, 0.78) * swellZone;
    float dCap = q.y - S - clawH;

    // The great crest: a lip that spirals over the hollow, thick at the back and thinning to the tip.
    float2 c = float2(-0.12, 0.47 + lift);
    float2 r2 = q - c;
    float rr = length(r2);
    float th = atan2(r2.y, r2.x);
    float s = (3.1416 - th) / 3.8;                            // 0 at the back of the curl, 1 at the lip
    float Ro = 0.41 - 0.1 * s * s + 0.012 * sin(time * 1.8 - s * 5.0);   // a ripple runs along the lip
    float T = lerp(0.3, 0.05, pow(saturate(s), 0.9));
    float dRing = max(max(rr - Ro, Ro - T - rr), (s - 1.0) * 0.9);
    float rf = Ro - T * 0.5 * smoothstep(0.06, 0.3, s);      // where the foam crown begins

    // Claws of foam along the outer edge of the lip, each finger bending forward around the curl.
    float arc = s * 1.37;
    float ci = floor(arc / 0.13);
    float kk = frac(arc / 0.13);
    float hgt = rr - Ro;
    float L = (0.05 + 0.035 * hash2(float2(ci, 3.0)) + 0.05 * s) * (1.0 + 0.6 * beat);
    float hn = saturate(hgt / L);
    float bend = 0.55 + 0.12 * sin(time * 2.4 + ci * 1.9);   // the fingers flex as the wave rolls
    float dClaw = max((abs(kk - 0.32 - bend * hn * hn) - 0.33 * (1.0 - pow(hn, 2.5))) * 0.13 * 0.8, max(hgt - L, -hgt - 0.03));
    dClaw = max(dClaw, max(0.2 - s, s - 1.04) * 0.5);

    // Union of everything carved: sea, lip and claws, and their colors.
    float dAll = min(min(dSea, dCap), min(dRing, dClaw));
    float band = floor(saturate(depth / 0.45) * 3.0) / 3.0;   // flat woodblock tones, darker with depth
    float3 sea = lerp(lerp(colorA.rgb * 1.1, colorA.rgb * 0.45, band), pale, step(depth, 0.045));
    float stripe = smoothstep(0.014, 0.004, abs(frac(depth / 0.085) - 0.5) * 0.085) * step(0.06, depth) * step(0.5, vnoise(float2(q.x * 7.0 + xo * 7.0, floor(depth / 0.085))));
    sea = lerp(sea, pale, stripe * 0.8);
    sea = lerp(sea, cream, saturate(step(depth, 0.05 * capM) + step(dCap, 0.0) * step(0.0, dSea)));
    float tr = saturate((rr - (Ro - T)) / max(T, 0.001));
    float3 lip = lerp(pale, colorA.rgb, smoothstep(0.05, 0.4, tr));
    lip = lerp(lip, pale, smoothstep(0.012, 0.004, abs(frac(tr * 3.0) - 0.5) * T / 3.0) * 0.8);
    lip = lerp(lip, cream, step(rf, rr));
    float3 col = dRing < min(dSea, dCap) ? lip : sea;
    col = lerp(col, cream, step(dClaw, dRing) * step(dClaw, 0.0));
    float ahead = smoothstep(0.25, 0.7, q.x);
    layer(acc, cover, col * (0.88 + 0.16 * grain), smoothstep(0.5 * aa, -0.5 * aa, dAll) * lerp(1.0, 0.4, ahead));
    float edge = smoothstep(lw * 0.5 + 0.5 * aa, lw * 0.5 - 0.5 * aa, abs(dAll + lw * 0.25));
    float foamEdge = smoothstep(lw * 0.4 + 0.5 * aa, lw * 0.4 - 0.5 * aa, abs(rr - rf)) * step(dRing, 0.0) * step(0.1, s);
    layer(acc, cover, ink, (edge + foamEdge * 0.8) * lerp(0.95, 0.45, ahead));

    // Spray: cream drops burst off the crest on the beat, fly out and fall as it fades.
    float burst = 1.0 - beat;
    float sr = (rr - 0.42 - 0.02 - 0.22 * burst) / 0.08;
    float2 sc = float2(floor(th / 0.22), floor(sr));
    float2 sl = float2((frac(th / 0.22) - 0.25 - 0.5 * hash2(sc + 3.1)) * 0.22 * rr, (frac(sr) - 0.5) * 0.08);
    float drop = length(sl + float2(0.0, 0.08 * burst * burst)) - (0.014 + 0.016 * beat);
    float sprayOn = step(hash2(sc + 17.0), 0.6) * step(0.0, sc.y) * step(sc.y, 2.0) * step(-0.9, th) * step(th, 2.4);
    layer(acc, cover, cream, smoothstep(0.5 * aa, -0.5 * aa, drop) * sprayOn * pow(beat, 0.6));

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