Rail Grind
by MusicBar, progress bar
A skater grinds a long handrail to the playhead with sparks spraying off the board and the shirt flapping, popping an ollie on every beat in front of a dim night city.
How it installs, its SHA-256 and its code
Click Apply: MusicBar downloads it, checks its SHA-256 and puts it on the taskbar, or just puts it on if it already has it. Needs MusicBar 1.8 or newer.
SHA-256 bc390ecbf0ca686494a4a22dd3e467d6eb5714d919030f1e1ba59a403499a6de
//! name: Rail Grind
//! author: MusicBar
//! kind: progress
//! description: A skater grinds a long handrail to the playhead with sparks spraying off the board and the shirt flapping, popping an ollie on every beat in front of a dim night city.
float hash1(float n) { return frac(sin(n * 127.1 + 311.7) * 43758.5453); }
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); }
// A two-bone limb from a to c, each bone l long; the joint bends to one side (+1 left of a to c, -1 right).
float limb(float2 p, float2 a, float2 c, float l, float side, float w0, float w1)
{
float2 dir = c - a;
float D = max(length(dir), 0.0001);
float2 j = 0.5 * (a + c) + float2(-dir.y, dir.x) / D * side * sqrt(max(l * l - 0.25 * D * D, 0.0));
return min(sdSeg(p, a, j) - w0, sdSeg(p, j, c) - w1);
}
// 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 = 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.3 * u, head - 1.2 * u, px.x);
float railY = 0.2 * u, rr = max(0.8, 0.03 * u);
float3 acc = float3(0, 0, 0);
float cover = 0;
// The city behind the played part: a hazy far row and a darker near row, windows lit at random.
for (int k = 0; k < 2; k++)
{
float fk = k, bw = (0.5 + 0.3 * fk) * u;
float x = px.x + time * (0.08 + 0.17 * fk) * u + fk * 13.0 * u;
float c = floor(x / bw), h = hash1(c * 1.7 + fk * 31.0);
float top = (0.62 + 0.36 * h - 0.2 * fk) * u;
float inB = step(px.y, top) * step(0.07, frac(x / bw)) * step(frac(x / bw), 0.93 + 0.07 * fk);
inB = max(inB, step(h, 0.3) * step(abs(frac(x / bw) - 0.6), 0.02) * step(px.y, top + 0.14 * u)); // an antenna now and then
float2 wc = floor(float2(x, px.y) / (float2(0.075, 0.1) * u));
float2 wf = frac(float2(x, px.y) / (float2(0.075, 0.1) * u));
float win = step(abs(wf.x - 0.5), 0.22) * step(abs(wf.y - 0.5), 0.24) * step(px.y, top - 0.06 * u);
float wh = hash1(wc.x * 7.3 + wc.y * 13.1 + fk * 5.0);
float lit = step(0.62, wh) * (0.6 + 0.4 * sin(time * (0.5 + wh * 2.0) + wh * 30.0));
float3 wall = lerp(float3(0.05, 0.06, 0.11), colorB.rgb * 0.25, 0.45) * (1.25 - 0.5 * fk);
layer(acc, cover, wall, inB * played * (0.45 + 0.25 * fk));
layer(acc, cover, lerp(float3(1.0, 0.8, 0.45), colorB.rgb, 0.3 * fk) * (0.7 + 0.4 * level), inB * win * lit * played * 0.75);
}
// The ledge under the rail, and the posts sliding by.
layer(acc, cover, float3(0.16, 0.16, 0.19) + float3(0.5, 0.5, 0.55) * smoothstep(1.5, 0.0, abs(px.y - 0.045 * u)), step(px.y, 0.045 * u) * lerp(0.25, 0.85, played));
float ps = 2.4 * u;
float pc = frac((px.x + time * 1.6 * u) / ps) * ps - 0.5 * ps;
float post = smoothstep(0.5, -0.5, abs(pc) - max(0.6, 0.022 * u)) * step(px.y, railY) * step(0.045 * u, px.y);
post = max(post, smoothstep(0.5, -0.5, abs(pc) - 0.05 * u) * step(0.045 * u, px.y) * step(px.y, 0.07 * u));
float3 steelP = lerp(float3(0.3, 0.32, 0.37), float3(0.75, 0.78, 0.85), saturate(0.5 - pc / (0.05 * u)));
layer(acc, cover, steelP * lerp(0.5, 1.0, played), post * lerp(0.35, 1.0, played));
// The rail: a lit steel tube, polished and still hot behind the board, dull ahead.
float dy = px.y - railY;
float back = max(head - px.x, 0.0);
float hot = exp(-back / (1.5 * u)) * step(px.x, head + 0.25 * u);
float3 steel = lerp(float3(0.22, 0.24, 0.3), float3(0.92, 0.94, 1.0), saturate(0.45 + 0.55 * dy / rr)) * lerp(0.55, 1.0, played);
steel = lerp(steel, lerp(colorC.rgb, float3(1.0, 0.95, 0.8), 0.4 * saturate(dy / rr + 0.5)), hot * 0.75);
layer(acc, cover, colorC.rgb, exp(-abs(dy) / (0.05 * u)) * hot * 0.5);
layer(acc, cover, float3(0.06, 0.06, 0.08), smoothstep(0.5, -0.5, abs(dy) - rr - 0.9));
layer(acc, cover, steel, smoothstep(0.5, -0.5, abs(dy) - rr));
// The ollie on the beat: the board pops nose-up and levels out, the rider tucks and rises less.
float ph = saturate(1.0 - beat) * step(0.02, beat);
float pop = sin(3.1416 * ph);
float tilt = 0.32 * sin(6.2832 * ph) * step(0.02, beat);
float onRail = 1.0 - saturate(pop * 3.0);
float2 deck = float2(head, railY + rr + 0.06 * u + 0.24 * u * pop);
// Sparks spraying back off the trucks, falling with gravity; more of them when the song is loud.
float sw = max(0.7, 0.016 * u);
for (int i = 0; i < 16; i++)
{
float fi = i;
float h1 = hash1(fi * 3.1 + 1.0), h2 = hash1(fi * 7.7 + 2.0);
float T = 0.5 * frac(time * (1.4 + 0.8 * h1) + h2);
float2 v = float2(-(0.8 + 3.0 * h1), 0.3 + 1.8 * h2) * u;
float2 o = float2(head - 0.19 * u + 0.38 * u * step(0.7, h2), railY + rr);
float2 sp = o + float2(v.x * T, v.y * T - 3.5 * u * T * T);
float2 vel = float2(v.x, v.y - 7.0 * u * T);
float sd = sdSeg(px, sp, sp - vel * 0.035);
float life = (1.0 - T / 0.5) * onRail * step(h1 * 0.9, 0.35 + 0.65 * level);
float3 sc = lerp(float3(1.0, 0.97, 0.85), lerp(colorC.rgb, float3(1.0, 0.3, 0.1), 0.3), T / 0.5);
layer(acc, cover, sc, (smoothstep(sw + 0.6, sw - 0.4, sd) * 1.3 + 0.5 * exp(-sd / (0.045 * u))) * life);
}
layer(acc, cover, lerp(colorC.rgb, float3(1, 1, 1), 0.6), (exp(-length(px - float2(head - 0.19 * u, railY + rr)) / (0.05 * u)) + exp(-length(px - float2(head + 0.19 * u, railY + rr)) / (0.05 * u))) * onRail * (0.6 + 0.4 * level));
// The board in its own frame: deck with kicked tails, trucks, wheels.
float2 b = rot(px - deck, -tilt) / u;
float dDeck = min(sdSeg(b, float2(-0.26, 0.0), float2(0.26, 0.0)), min(sdSeg(b, float2(0.26, 0.0), float2(0.33, 0.055)), sdSeg(b, float2(-0.26, 0.0), float2(-0.33, 0.055)))) - 0.018;
float dTruck = max(abs(abs(b.x) - 0.19) - 0.035 + (b.y + 0.018) * 0.6, abs(b.y + 0.035) - 0.02);
float dWheel = length(float2(abs(b.x) - 0.19, b.y + 0.06)) - 0.028;
layer(acc, cover, float3(0.05, 0.05, 0.07), smoothstep(0.5, -0.5, min(dDeck, min(dTruck, dWheel)) * u - 1.1));
layer(acc, cover, float3(0.75, 0.77, 0.82), smoothstep(0.5, -0.5, dTruck * u));
layer(acc, cover, lerp(float3(0.95, 0.92, 0.85), colorC.rgb, 0.25) * (0.7 + 0.3 * saturate(-(b.y + 0.06) / 0.03 + 0.5)), smoothstep(0.5, -0.5, dWheel * u));
float3 deckC = lerp(colorC.rgb * 0.9, float3(0.08, 0.08, 0.1), smoothstep(-0.004, 0.006, b.y)); // graphic underneath, grip tape on top
layer(acc, cover, deckC, smoothstep(0.5, -0.5, dDeck * u));
// The rider, in bar heights from the middle of the deck: feet ride the board, hips rise less on the pop.
float2 q = (px - float2(head, railY + rr + 0.075 * u)) / u;
float2 fF = rot(float2(0.15, 0.0), tilt) + float2(0.0, 0.24 * pop + 0.012);
float2 fB = rot(float2(-0.15, 0.0), tilt) + float2(0.0, 0.24 * pop + 0.012);
float2 hip = float2(-0.01, 0.27 + 0.07 * pop + 0.008 * sin(time * 7.0) * level);
float2 sh = hip + float2(0.075, 0.19);
float2 hd = sh + float2(0.045, 0.095);
float2 hF = sh + float2(0.24, -0.02 + 0.03 * sin(time * 2.6) + 0.12 * pop);
float2 hB = sh + float2(-0.25, 0.07 + 0.03 * sin(time * 2.1 + 1.0) + 0.1 * pop);
float dLegs = min(limb(q, hip + float2(0.04, 0.0), fF, 0.17, 1.0, 0.052, 0.04), limb(q, hip - float2(0.03, 0.0), fB, 0.17, -1.0, 0.052, 0.04));
float dShoes = min(ellipse(q - fF - float2(0.025, 0.024), float2(0.06, 0.027)), ellipse(q - fB - float2(-0.015, 0.024), float2(0.06, 0.027)));
float dArms = min(limb(q, sh, hF, 0.135, -1.0, 0.032, 0.025), limb(q, sh, hB, 0.135, 1.0, 0.032, 0.025));
float dCap = ellipse(q - hd - float2(-0.008, 0.026), float2(0.068, 0.05));
float dHead = min(length(q - hd) - 0.062, dCap);
float tl = (q.y - hip.y) / (sh.y - hip.y);
float behind = step(q.x, lerp(hip.x, sh.x, saturate(tl)));
float flap = (0.02 + 0.08 * saturate(1.0 - tl)) * (0.6 + 0.4 * sin(time * 30.0 - q.y * 45.0)) * (1.0 + 0.5 * pop);
float dShirt = min(sdSeg(q + float2(flap * behind, 0.0), hip + float2(0.0, 0.0), sh) - 0.07, sdSeg(q, sh, lerp(sh, hF, 0.32)) - 0.042);
dShirt = min(dShirt, sdSeg(q, sh, lerp(sh, hB, 0.32)) - 0.042);
float dAll = min(min(min(dLegs, dShoes), min(dArms, dHead)), dShirt);
// Rim light from the edge normal: cool city light from above-behind, warm spark light from below.
float2 g = float2(ddx(dAll), -ddy(dAll));
float2 nrm = g / max(length(g), 0.00001);
float band = smoothstep(-0.03, -0.004, dAll);
float3 rimC = lerp(colorB.rgb, float3(1, 1, 1), 0.35) * saturate(dot(nrm, float2(-0.55, 0.83))) + colorC.rgb * saturate(dot(nrm, float2(-0.6, -0.8))) * onRail * 1.2;
// A soft glow and dark outline so the silhouette holds on any taskbar, then the rider.
layer(acc, cover, lerp(colorB.rgb, colorA.rgb, 0.3), exp(-max(dAll, 0.0) / 0.07) * 0.25);
layer(acc, cover, float3(0.02, 0.02, 0.04), smoothstep(0.5, -0.5, dAll * u - 1.1));
float3 pants = lerp(float3(0.06, 0.07, 0.11), colorB.rgb * 0.3, 0.4) * (0.8 + 0.4 * saturate(q.y / 0.3));
layer(acc, cover, pants + rimC * band, smoothstep(0.5, -0.5, dLegs * u));
layer(acc, cover, lerp(float3(0.1, 0.1, 0.13), float3(0.92, 0.92, 0.95), step(q.y, fF.y + 0.016)) + rimC * band * 0.5, smoothstep(0.5, -0.5, dShoes * u));
layer(acc, cover, float3(0.08, 0.07, 0.1) + rimC * band, smoothstep(0.5, -0.5, min(dArms, dHead) * u));
float3 shirt = colorA.rgb * (0.5 + 0.5 * saturate((q.x - hip.x) / 0.1 + 0.4)) * (0.85 + 0.15 * sin(q.y * 70.0 - time * 30.0) * behind);
layer(acc, cover, shirt + rimC * band * 0.6, smoothstep(0.5, -0.5, dShirt * u));
layer(acc, cover, lerp(colorA.rgb, colorB.rgb, 0.5) * 0.55 + rimC * band * 0.6, smoothstep(0.5, -0.5, dCap * u) * step(hd.y + 0.01, q.y));
return paint(acc / max(cover, 0.001), cover);
}