Duck Parade
của MusicBar, thanh tiến trình
Vịt mẹ bơi tới chỗ đang phát, kéo theo hàng vịt con lon ton phía sau, bài càng chạy đàn con càng dài, cứ tới nhịp là cả đám nhún nhún trên mặt hồ.
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 50aab8eaa660c1dd88f1c4c9e4bf707e3624a9c4328d501c1e417636ae1f8644
//! name: Duck Parade
//! author: MusicBar
//! kind: progress
//! description: A mother duck paddles to the playhead with a growing line of fluffy ducklings behind her, every one bobbing on the beat and trailing its own little wake across the pond.
// A steady random number for a whole number.
float hash1(float n) { n = frac(n * 0.1031); n *= n + 33.33; n *= n + n; return frac(n); }
// Turns a point around the origin by a (radians, counterclockwise).
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 to an ellipse with radii r (close enough near the edge).
float ellipse(float2 p, float2 r) { float k0 = length(p / r); return k0 * (k0 - 1.0) / max(length(p / (r * r)), 0.0001); }
// Signed distance to a rounded box (half size b, corner r).
float boxD(float2 p, float2 b, float r) { float2 d = abs(p) - b + r; return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - r; }
// Smooth union, so neck, head and tail melt into the body.
float smin(float a, float b, float k) { float h = saturate(0.5 + 0.5 * (b - a) / k); return lerp(b, a, h) - k * h * (1.0 - h); }
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))); }
// Anti-aliased fill of a distance d, where pw is one pixel in the same units.
float fill(float d, float pw) { return smoothstep(0.6 * pw, -0.6 * pw, d); }
// Round shading for an ellipse part: key light from the upper left, a soft rim, a glint.
float3 ball(float2 q, float2 c, float2 r, float3 base)
{
float2 s = (q - c) / r;
float z = sqrt(saturate(1.0 - dot(s, s)));
float3 n = normalize(float3(s, z + 0.05));
float dif = saturate(dot(n, normalize(float3(-0.35, 0.7, 0.6))));
return base * (0.5 + 0.6 * dif) + pow(saturate(dot(n, normalize(float3(-0.3, 0.6, 1.0)))), 24.0) * 0.22 + colorA.rgb * pow(1.0 - z, 3.0) * 0.25;
}
// 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 swimmer at x0 on the waterline wy: its wake, beat ring, reflection and body. s is its size in bar heights;
// mom picks the mother's long neck and white plumage over a duckling's round fluff.
void duck(inout float3 acc, inout float cover, float2 px, float x0, float wy, float s, float mom, float k)
{
float u = size.y, pw = 1.0 / (u * s), wl = 0.3 * u;
float inW = step(px.y, wl);
// Wake: a flattened V of two wavy lines spreading back from the tail, fading as it goes.
float dx = (x0 - (0.25 + 0.17 * mom) * u * s - px.x) / u;
float vee = abs(abs(px.y - wy) / u - dx * 0.24 - 0.012 * sin(dx * 30.0 - time * 7.0));
float3 foam = lerp(colorA.rgb, float3(1, 1, 1), 0.7);
layer(acc, cover, foam, smoothstep(0.014 + 0.7 / u, 0.0, vee) * exp(-dx / (0.45 + 0.25 * mom)) * step(0.0, dx) * inW * 0.7);
// A ring that bursts out from under it on the beat.
float2 rq = (px - float2(x0, wy)) / u;
float rr = (0.22 + 0.45 * (1.0 - beat)) * (0.8 + 0.4 * mom);
layer(acc, cover, foam, smoothstep(0.015 + 0.8 / u, 0.0, abs(ellipse(rq, float2(rr, rr * 0.24)))) * beat * inW * 0.9);
// The duck's frame: facing the playhead, bobbing idly, dipping and nodding forward on the beat.
float2 q = (px - float2(x0, wy)) / (u * s);
q.y -= 0.012 * sin(time * 2.4 + k * 1.1) - (0.035 + 0.02 * (1.0 - mom)) * beat;
q = rot(q, (0.12 + 0.1 * (1.0 - mom)) * beat);
float2 bc = lerp(float2(0.0, 0.1), float2(-0.05, 0.1), mom), br = lerp(float2(0.2, 0.13), float2(0.36, 0.17), mom);
float2 hc = lerp(float2(0.12, 0.27), float2(0.24, 0.5), mom);
float hr = lerp(0.1, 0.11, mom);
float2 tq = rot(q - lerp(float2(-0.18, 0.15), float2(-0.36, 0.2), mom), lerp(0.6, 0.55, mom));
float dBody = smin(ellipse(q - bc, br), ellipse(tq, lerp(float2(0.06, 0.03), float2(0.12, 0.045), mom)), 0.05);
float dNeck = sdSeg(q, float2(0.14, 0.2), float2(0.23, 0.44)) - 0.075 + 9.0 * (1.0 - mom);
float dHead = length(q - hc) - hr;
float dDuck = smin(smin(dBody, dNeck, 0.06), dHead, 0.05);
float2 bq = rot(q - hc - lerp(float2(0.115, -0.015), float2(0.13, -0.025), mom), 0.15);
float dBill = boxD(bq, lerp(float2(0.05, 0.022), float2(0.075, 0.027), mom), 0.02);
// The water cuts it at a wavy line; below, a wobbly reflection.
float wob = 0.006 * sin(q.x * 30.0 + time * 3.0 + k);
float above = smoothstep(-0.6 * pw, 0.6 * pw, q.y - wob);
float2 mq = float2(q.x + 0.01 * sin(q.y * 40.0 - time * 4.0), -q.y);
float dRef = min(min(ellipse(mq - bc, br), length(mq - hc) - hr), sdSeg(mq, float2(0.14, 0.2), float2(0.23, 0.44)) - 0.075 + 9.0 * (1.0 - mom));
float3 plume = lerp(lerp(float3(1.0, 0.86, 0.3), colorC.rgb, 0.4), float3(0.97, 0.96, 0.93), mom);
layer(acc, cover, plume * 0.55, fill(dRef, pw) * (1.0 - above) * smoothstep(-0.35, 0.0, q.y) * 0.4);
// Outline for light taskbars, then the body, the wing, head and bill.
layer(acc, cover, float3(0.14, 0.12, 0.18), fill(min(dDuck, dBill) - 1.5 * pw, pw) * above);
float3 col = lerp(ball(q, bc, br, plume), ball(q, hc, float2(hr, hr), plume), smoothstep(0.03, -0.03, dHead - dBody));
col = lerp(col, ball(q, float2(0.185, 0.32), float2(0.1, 0.2), plume), smoothstep(0.03, -0.03, dNeck - min(dBody, dHead)) * mom);
layer(acc, cover, col, fill(dDuck, pw) * above);
// The wing lifts on the beat; the mother's carries a band of the second color along its lower edge.
float2 wq = rot(q - float2(lerp(-0.04, -0.09, mom), lerp(0.13, 0.16, mom)), -0.12 - 0.35 * beat);
float2 wr = lerp(float2(0.12, 0.065), float2(0.22, 0.085), mom);
float dWing = ellipse(wq, wr);
float3 wcol = ball(wq, float2(0, 0), wr, plume * lerp(0.88, 0.93, mom));
wcol = lerp(wcol, colorB.rgb, smoothstep(0.012, 0.004, abs(dWing + 0.02)) * smoothstep(0.0, -0.03, wq.y) * smoothstep(0.05, -0.05, wq.x) * mom);
layer(acc, cover, wcol, fill(dWing, pw) * above);
layer(acc, cover, plume * 0.5, fill(abs(dWing + 0.004) - 0.5 * pw, pw) * above * 0.5);
layer(acc, cover, float3(1.0, 0.6, 0.16) * (0.75 + 0.35 * saturate(bq.y / 0.03 + 0.5)), fill(dBill, pw) * above);
// A tuft on the ducklings' heads, and the eye with a glint.
layer(acc, cover, plume * 0.9, fill(ellipse(rot(q - hc - float2(-0.01, 0.1), 0.4), float2(0.018, 0.04)), pw) * (1.0 - mom) * above);
float2 eq = q - hc - float2(0.035, 0.025);
layer(acc, cover, float3(0.06, 0.05, 0.08), fill(length(eq) - 0.024, pw) * above);
layer(acc, cover, float3(1, 1, 1), fill(length(eq - float2(0.007, 0.009)) - 0.008, pw) * above);
// Where the body meets the water: a bright little line.
layer(acc, cover, foam, smoothstep(0.02, 0.0, abs(q.y - wob)) * step(dDuck, 0.01) * 0.7);
}
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 ducks always swim upright
float head = progress * size.x;
float wl = 0.3 * u, wy = 0.12 * u; // the pond's far edge, and where the ducks float
float3 acc = float3(0, 0, 0);
float cover = 0;
// The pond: dim and calm ahead, brighter and alive where the parade has passed.
float played = smoothstep(head + 0.4 * u, head - 0.2 * u, px.x);
float wv = px.y / wl, inW = step(px.y, wl);
layer(acc, cover, lerp(colorA.rgb * lerp(0.2, 0.35, played), colorA.rgb * lerp(0.4, 0.75, played), wv), inW * lerp(0.16, 0.55, played) * lerp(1.0, 0.7, wv));
float shim = pow(saturate(sin(px.x / u * 5.0 + sin(px.x / u * 1.7 + time * 0.5) * 2.0 + wv * 9.0 - time * 0.8) * 0.5 + 0.5), 16.0);
layer(acc, cover, lerp(colorA.rgb, float3(1, 1, 1), 0.6), shim * inW * lerp(0.06, 0.3, played));
layer(acc, cover, lerp(colorA.rgb, float3(1, 1, 1), 0.4), smoothstep(1.2, 0.0, abs(px.y - wl)) * lerp(0.15, 0.55, played));
// Lily pads, seen at a low angle; lush behind the ducks, dark shapes ahead.
float lw = 1.9 * u, lc = floor(px.x / lw), lh = hash1(lc * 3.3 + 1.0);
float2 lq = (px - float2((lc + 0.2 + 0.6 * hash1(lc * 7.7)) * lw, (0.06 + 0.15 * lh) * u)) / u / float2(1.0, 0.36);
float lr = 0.13 + 0.05 * hash1(lc * 5.1), ll = length(lq);
float la = atan2(lq.y, lq.x) + lh * 6.2832;
la = abs(la - 6.2832 * floor(la / 6.2832 + 0.5));
float dPad = max(ll - lr, -ll * sin(min(la - 0.3, 1.5))) * 0.5;
float3 padCol = lerp(float3(0.07, 0.14, 0.1), lerp(float3(0.2, 0.45, 0.2), float3(0.45, 0.75, 0.35), saturate(lq.y / lr * 0.5 + 0.5)), played);
layer(acc, cover, padCol, fill(dPad * u, 1.0) * step(0.35, lh) * lerp(0.45, 0.95, played));
// Sun glints dancing on the water the parade has stirred.
float gc = floor(px.x / (0.4 * u)), gh = hash1(gc * 9.1 + 4.0);
float2 gq = (px - float2((gc + 0.5) * 0.4 * u, (0.04 + 0.22 * hash1(gc * 1.7)) * u)) / u;
float tw = pow(saturate(sin(time * 2.5 + gh * 30.0)), 6.0) * (0.6 + 0.6 * level);
float star = exp(-length(gq) / 0.015) + exp(-abs(gq.y) / 0.004 - abs(gq.x) / 0.05) * 0.6;
layer(acc, cover, lerp(colorC.rgb, float3(1, 1, 1), 0.6), star * tw * played * step(0.45, gh) * inW);
// The line of ducklings: one every little way behind the mother, as far back as the song has come.
float D = 0.8 * u, xm = head - 0.3 * u, x1 = xm - 0.82 * u;
float kA = max(floor((x1 - px.x) / D), 0.0), kB = kA + 1.0;
duck(acc, cover, px, x1 - kB * D + 0.05 * u * sin(time * 1.4 + kB * 1.7), wy, 1.0, 0.0, kB);
duck(acc, cover, px, x1 - kA * D + 0.05 * u * sin(time * 1.4 + kA * 1.7), wy, 1.0, 0.0, kA);
// The mother at the playhead, pushing a little bow wave.
float2 bw = (px - float2(xm + 0.32 * u, wy)) / u;
float bow = abs(length(bw * float2(1.0, 3.2)) - 0.12 - 0.08 * frac(time * 1.5));
layer(acc, cover, lerp(colorA.rgb, float3(1, 1, 1), 0.7), smoothstep(0.015 + 0.7 / u, 0.0, bow) * step(0.0, bw.x) * (1.0 - frac(time * 1.5)) * 0.8);
duck(acc, cover, px, xm, wy, 1.15, 1.0, -1.0);
return paint(acc / max(cover, 0.001), cover);
}