Goal Run
của MusicBar, thanh tiến trình
Trái bóng lăn tròn trên sân cỏ kẻ sọc tới chỗ đang phát, cứ tới nhịp là nảy lên một cái, khán đài phía sau lóe flash lia lịa, khung thành đứng chờ ở cuối thanh.
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 3f4aace2bddf38033213208f9df751d7b189ed1997baca360f2beae38fd64aa8
//! name: Goal Run
//! author: MusicBar
//! kind: progress
//! description: A football rolls and spins down a striped night pitch to the playhead, hopping on every beat, while camera flashes twinkle in the stands and a goal net waits at the far end.
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); }
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); }
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 ellipse(float2 p, float2 r) { float k0 = length(p / r); return k0 * (k0 - 1.0) / max(length(p / (r * r)), 0.0001); }
// Distance outside one edge of a counterclockwise polygon (negative inside).
float edge(float2 p, float2 a, float2 b) { float2 e = normalize(b - a); return e.y * (p.x - a.x) - e.x * (p.y - a.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);
}
// Patch centers of a classic ball: 6 pentagons then 10 hexagons, each also standing for its opposite point.
static const float3 PATCH[16] = {
float3(0, 0.5257, 0.8507), float3(0, 0.5257, -0.8507), float3(0.5257, 0.8507, 0), float3(0.5257, -0.8507, 0),
float3(0.8507, 0, 0.5257), float3(0.8507, 0, -0.5257), float3(0.5774, 0.5774, 0.5774), float3(0.5774, 0.5774, -0.5774),
float3(0.5774, -0.5774, 0.5774), float3(-0.5774, 0.5774, 0.5774), float3(0.3568, 0, 0.9342), float3(0.3568, 0, -0.9342),
float3(0.9342, 0.3568, 0), float3(0.9342, -0.3568, 0), float3(0, 0.9342, 0.3568), float3(0, 0.9342, -0.3568) };
// For a point on the ball: is it on a pentagon (x), is the neighbor patch one (y), angle to the seam (z).
float3 ballSkin(float3 n)
{
float m1 = 9.0, m2 = 9.0, t1 = 0.0, t2 = 0.0;
for (int i = 0; i < 16; i++)
{
float isPent = i < 6 ? 1.0 : 0.0;
float m = acos(min(abs(dot(n, PATCH[i])), 1.0)) - lerp(0.3648, 0.2875, isPent);
float nearer = step(m, m1), second = (1.0 - nearer) * step(m, m2);
m2 = lerp(lerp(m2, m, second), m1, nearer);
t2 = lerp(lerp(t2, isPent, second), t1, nearer);
t1 = lerp(t1, isPent, nearer);
m1 = min(m1, m);
}
return float3(t1, t2, (m2 - m1) * 0.5);
}
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
float head = progress * size.x;
float played = smoothstep(head + 0.4 * u, head - 0.8 * u, px.x);
float gx = size.x - 0.62 * u; // the near goal post
float px2 = px.x + 1.2 * px.y; // along the pitch's cross lines, seen in perspective
float lw = max(0.6, 0.016 * u), pw = max(1.0, 0.032 * u); // chalk and goal post half widths
float3 acc = float3(0, 0, 0);
float cover = 0;
// The stands: a dark tier behind the played part with two rows of supporters bobbing to the music.
float stand = step(0.37 * u, px.y) * played;
layer(acc, cover, lerp(float3(0.03, 0.035, 0.07), colorB.rgb * 0.18, 0.4), stand * 0.5);
for (int k = 0; k < 2; k++)
{
float cw = 0.15 * u, fk = k;
float c = floor((px.x + fk * 0.07 * u) / cw);
float h = hash2(float2(c, fk + 3.0)), h2 = hash2(float2(c, fk + 9.0));
float2 hc = float2((c + 0.5 + 0.3 * (h - 0.5)) * cw - fk * 0.07 * u, (0.82 - 0.24 * fk + 0.05 * h) * u + 0.03 * u * level * sin(time * 9.0 + c * 1.7));
float2 dq = px - hc;
float shoulders = min((length((dq + float2(0.0, 0.12 * u)) / float2(0.064, 0.06)) - u) * 0.062, max(abs(dq.x) - 0.064 * u, dq.y + 0.12 * u));
float cheer = saturate(beat * 1.6) * step(0.5, h2) + 0.25 * step(0.9, h2); // fans throw their arms up on the beat
float arms = sdSeg(float2(abs(dq.x), dq.y), float2(0.045 * u, -0.08 * u), float2(0.06 * u + 0.03 * u * cheer, -0.08 * u + 0.22 * u * cheer)) - 0.016 * u;
float body = min(min(length(dq) - 0.046 * u, shoulders), lerp(9.0, arms, step(0.05, cheer)));
float3 fan = lerp(float3(0.07, 0.08, 0.13), lerp(colorA.rgb, colorB.rgb, step(0.5, h)) * 0.35, 0.5) * (1.0 + 0.5 * fk);
fan *= 1.0 + 1.2 * smoothstep(-0.02 * u, 0.04 * u, dq.y) * step(length(dq), 0.05 * u); // floodlight on the heads
layer(acc, cover, fan, smoothstep(0.5, -0.5, body) * stand * 0.9);
}
// Camera flashes popping in the crowd, a burst of extra ones on the beat.
float fs = 0.21 * u;
float2 fc = floor(px / fs);
float fr = 0.4 + 0.3 * hash2(fc + 4.1);
float fe = time * fr + hash2(fc + 8.7) * 9.0;
float fon = saturate(1.0 - frac(fe) / 0.08) * step(0.35, hash2(fc + floor(fe)));
fon = max(fon, beat * step(0.62, hash2(fc + floor(time * 3.0) * 1.3)));
float2 fd = abs(px - (fc + 0.2 + 0.6 * float2(hash2(fc + 1.3), hash2(fc + 2.9))) * fs);
float flash = exp(-length(fd) / (0.02 * u)) + 0.35 * exp(-length(fd) / (0.06 * u)) + exp(-fd.x / 0.8 - fd.y / (0.09 * u)) + exp(-fd.y / 0.8 - fd.x / (0.09 * u));
layer(acc, cover, lerp(colorC.rgb, float3(1, 1, 1), 0.6), flash * fon * step(0.42 * u, px.y) * stand);
// Perimeter LED boards between the stands and the pitch, pulsing with the beat.
float led = step(0.29 * u, px.y) * step(px.y, 0.37 * u) * step(0.04, frac(px.x / (2.4 * u)));
float3 ledC = lerp(colorA.rgb, colorB.rgb, 0.5 + 0.5 * sin(px.x / u * 1.4 - time * 3.0)) * (0.6 + 0.5 * level + 0.7 * beat);
layer(acc, cover, ledC * (0.85 + 0.15 * step(0.5, frac(px.y / 2.0))), led * lerp(0.15, 0.9, played));
// The pitch: mowed stripes in perspective, rich behind the ball and only a faint promise ahead.
float pitch = step(px.y, 0.29 * u), stripe = step(0.5, frac(px2 / (0.8 * u)));
float3 grass = lerp(float3(0.1, 0.42, 0.16), colorA.rgb * 0.55, 0.2) * (0.78 + 0.28 * stripe);
grass *= (0.88 + 0.2 * hash2(floor(px * float2(0.5, 1.0)))) * (1.0 - 0.3 * px.y / (0.29 * u)); // turf grain
layer(acc, cover, grass, pitch * lerp(0.2, 0.92, played));
// Chalk: the two touchlines, the halfway line and center circle, the penalty box and goal line at the end.
float cx = size.x * 0.5;
float chalk = smoothstep(lw + 0.5, lw - 0.5, min(abs(px.y - 0.04 * u), abs(px.y - 0.27 * u)));
chalk = max(chalk, smoothstep(lw + 0.5, lw - 0.5, abs(px2 - cx - 0.18 * u)));
chalk = max(chalk, smoothstep(lw + 0.5, lw - 0.5, abs(ellipse(px - float2(cx, 0.155 * u), float2(0.75, 0.095) * u))));
float box = min(abs(px2 - gx + 1.5 * u), max(min(abs(px.y - 0.08 * u), abs(px.y - 0.23 * u)), px2 - gx));
box = min(max(box, max(0.075 * u - px.y, px.y - 0.235 * u)), abs(px2 - gx - 0.06 * u));
chalk = max(chalk, smoothstep(lw + 0.5, lw - 0.5, box) * step(gx - 1.5 * u - lw, px2));
layer(acc, cover, float3(0.95, 0.97, 0.94), chalk * pitch * lerp(0.35, 0.85, played));
// The goal: a net mesh billowing a little, then the posts and the crossbar, outlined for light taskbars.
float nd = max(max(edge(px, float2(gx - 0.3 * u, 0.27 * u), float2(gx, 0.05 * u)), edge(px, float2(gx, 0.05 * u), float2(gx + 0.55 * u, 0.05 * u))),
max(edge(px, float2(gx + 0.55 * u, 0.05 * u), float2(gx + 0.55 * u, 0.6 * u)), max(edge(px, float2(gx + 0.55 * u, 0.6 * u), float2(gx + 0.15 * u, 0.86 * u)), edge(px, float2(gx + 0.15 * u, 0.86 * u), float2(gx - 0.3 * u, 0.98 * u)))));
nd = max(nd, gx - 0.3 * u - px.x); // the far post closes the mouth
float2 nm = px + float2(0.03 * u * sin(px.y / u * 9.0 + time * 2.0) * (0.3 + level), 0.0);
float ms = max(0.1 * u, 6.0);
float2 mf = 0.5 - abs(frac(float2(nm.x + nm.y, nm.x - nm.y) / ms) - 0.5);
float mesh = smoothstep(1.0, 0.3, min(mf.x, mf.y) * ms * 0.707);
float net = smoothstep(0.5, -0.5, nd);
layer(acc, cover, float3(0.02, 0.03, 0.05), net * 0.3);
layer(acc, cover, float3(0.9, 0.92, 0.95), net * mesh * 0.55);
float frame = min(min(sdSeg(px, float2(gx, 0.05 * u), float2(gx, 0.76 * u)), sdSeg(px, float2(gx - 0.3 * u, 0.27 * u), float2(gx - 0.3 * u, 0.97 * u))), sdSeg(px, float2(gx, 0.76 * u), float2(gx - 0.3 * u, 0.97 * u)));
layer(acc, cover, float3(0.1, 0.1, 0.12), smoothstep(0.5, -0.5, frame - pw - 1.0));
layer(acc, cover, float3(0.97, 0.97, 1.0) * (0.75 + 0.25 * saturate((px.x - gx + pw) / pw)), smoothstep(0.5, -0.5, frame - pw));
// The ball: it rolls along the grass, spinning faster when the song is loud, and pops up on every beat.
float r = 0.24 * u;
float hop = sin(3.1416 * saturate(1.0 - beat)) * step(0.02, beat);
float2 bc = float2(head, 0.12 * u + r + 0.32 * u * hop);
float spin = time * 6.5 + head / r;
// Its shadow on the grass, and speed streaks trailing behind it.
float2 sq = (px - float2(head + 0.04 * u, 0.12 * u)) / float2(r * (1.0 - 0.35 * hop), 0.05 * u);
layer(acc, cover, float3(0.0, 0.03, 0.0), exp(-dot(sq, sq) * 1.5) * (0.6 - 0.35 * hop));
float row = floor((px.y - bc.y) / (0.09 * u) + 0.5);
float rh = hash2(float2(row, floor(time * 6.0)));
float sl = (0.5 + 0.9 * rh) * u * (0.5 + 0.7 * level);
float back = head - r * 0.5 - px.x;
float streak = step(abs(row), 2.0) * step(0.0, back) * saturate(1.0 - back / sl) * smoothstep(lw + 0.6, lw - 0.4, abs(px.y - bc.y - row * 0.09 * u));
layer(acc, cover, float3(1, 1, 1), streak * step(0.3, rh) * 0.45);
float2 s = (px - bc) / r;
float d = length(s);
float3 n = float3(s, sqrt(saturate(1.0 - d * d)));
float3 nb = float3(rot(n.xy, spin), n.z); // roll with the spin, then tip the pattern toward us
nb.yz = rot(nb.yz, 0.6);
float3 sk = ballSkin(nb);
float aw = 1.2 / r; // about one pixel, as an angle on the ball
float pent = lerp(sk.y, sk.x, 0.5 + 0.5 * saturate(sk.z / aw));
float3 ball = lerp(float3(0.96, 0.96, 0.93), lerp(float3(0.05, 0.05, 0.07), colorB.rgb * 0.3, 0.25), pent);
ball *= 1.0 - 0.45 * smoothstep(aw, 0.0, sk.z) * saturate((r - 7.0) / 10.0); // seams only where there is room
float dif = saturate(dot(n, normalize(float3(-0.45, 0.6, 0.65))));
float spec = pow(saturate(dot(n, normalize(float3(-0.3, 0.5, 1.0)))), 30.0);
ball = ball * (0.3 + 0.8 * dif) + spec * 0.7 + lerp(colorC.rgb, float3(1, 1, 1), 0.4) * pow(1.0 - n.z, 3.0) * saturate(0.3 + n.x) * 0.8;
layer(acc, cover, float3(1, 1, 1), exp(-max(d - 1.0, 0.0) * r / (0.09 * u)) * 0.22 * (0.6 + 0.4 * level));
layer(acc, cover, float3(0.05, 0.06, 0.08), smoothstep(0.5, -0.5, (d - 1.0) * r - 1.2));
layer(acc, cover, ball, smoothstep(0.5, -0.5, (d - 1.0) * r));
return paint(acc / max(cover, 0.001), cover);
}