Stained Glass
của MusicBar, thanh tiến trình
Kính màu nhà thờ sáng dần từng mảnh tới ô cửa sổ hoa hồng ở chỗ đang phát, phía trước kính còn tối om, cứ tới nhịp là vệt nắng chéo rọi qua sáng bừng.
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 01bb60c611be3b023f563def62f6c1aecea8ce01182573350377d1b1b35110ef
//! name: Stained Glass
//! author: MusicBar
//! kind: progress
//! description: Cathedral glass lights up piece by piece in jewel tones behind a glowing rose window at the playhead, light shafts flare through it on every beat and the glass ahead waits dark.
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);
}
// The seed point of glass cell n (in cell units), jittered so the pieces are irregular.
float2 seed(float2 n)
{
return n + 0.5 + 0.36 * sin(6.2831 * float2(hash2(n), hash2(n + 19.19)));
}
// A jewel tone for piece h: the palette and its hue-turned cousins (channels swapped), richly saturated.
float3 jewel(float h)
{
float3 c = h < 0.3 ? colorA.rgb : (h < 0.52 ? colorB.rgb : (h < 0.68 ? colorC.rgb : (h < 0.85 ? colorA.brg : colorC.gbr)));
float g = dot(c, float3(0.3, 0.59, 0.11));
return saturate(lerp(float3(g, g, g), c, 1.35));
}
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 light falls from above
float head = progress * size.x;
float cs = u * 0.42; // glass piece size
float hw = max(0.75, 0.04 * u); // half width of the lead came
// Voronoi glass: the nearest seed gives the piece, a second pass the distance to its lead border.
float2 g = px / cs;
float2 n = floor(g);
float2 mr = float2(0, 0);
float2 mo = float2(0, 0);
float md = 9.0;
[unroll] for (int j = -1; j <= 1; j++)
[unroll] for (int i = -1; i <= 1; i++)
{
float2 o = float2(i, j);
float2 r = seed(n + o) - g;
float closer = step(dot(r, r), md);
md = lerp(md, dot(r, r), closer);
mr = lerp(mr, r, closer);
mo = lerp(mo, o, closer);
}
float ed = 9.0;
[unroll] for (int j2 = -1; j2 <= 1; j2++)
[unroll] for (int i2 = -1; i2 <= 1; i2++)
{
float2 r = seed(n + mo + float2(i2, j2)) - g;
float2 dr = r - mr;
ed = dot(dr, dr) > 0.0001 ? min(ed, dot(0.5 * (mr + r), normalize(dr))) : ed;
}
float2 cid = n + mo;
float edPx = min(ed * cs, min(px.y, u - px.y) - hw * 0.6); // the frame runs along both long edges
// Each piece catches the light once the playhead passes its middle, flickering as it does.
float cx = seed(cid).x * cs;
float on = smoothstep(0.0, 0.4, (head - cx) / u - 0.05);
float nearHead = exp(-max(head - px.x, 0.0) / (1.6 * u));
on *= lerp(0.6 + 0.4 * sin(time * 31.0 + cid.x * 3.0), 1.0, step(0.999, on));
// The glass: a jewel tone, mottled and rippled like hand-blown sheet, darker toward the lead.
float h = hash2(cid + 7.7);
float3 tone = jewel(h);
float2 w = px / u;
float mott = vnoise(w * 5.0 + h * 40.0) * 0.6 + vnoise(w * 13.0 - h * 20.0) * 0.4;
float ripple = sin(dot(w, float2(cos(h * 6.0), sin(h * 6.0))) * 24.0 + mott * 5.0);
float inner = smoothstep(0.0, 0.32 * u, edPx);
float sx = (px.x + px.y * 1.1) / u; // light shafts slant down from the upper left
float shaft = pow(0.5 + 0.5 * sin(sx * 0.55 - time * 0.3), 14.0) + 0.8 * pow(0.5 + 0.5 * sin(sx * 1.3 + 1.0 - time * 0.4), 20.0);
shaft *= 0.3 + 1.3 * beat + 0.25 * level;
float light = (0.5 + 0.5 * mott + 0.06 * ripple) * (0.55 + 0.45 * inner) * (1.0 + 0.6 * nearHead);
float3 lit = tone * light * (1.0 + 0.5 * shaft) + float3(1.0, 0.95, 0.82) * shaft * 0.5 * (0.4 + 0.6 * inner);
float3 dark = tone * 0.14 * (0.7 + 0.5 * mott) + 0.02;
float3 acc = float3(0, 0, 0);
float cover = 0;
float aa = 0.5;
float glassA = smoothstep(-aa, aa, edPx - hw);
layer(acc, cover, lerp(dark, lit, on), glassA * lerp(0.2, 0.92, on));
// Lead came: dark grey with a dull shine along its middle, a little warmer where the light comes through.
float leadA = smoothstep(aa, -aa, edPx - hw) * step(0.0, edPx + hw * 1.6);
float3 lead = float3(0.1, 0.1, 0.11) + float3(0.24, 0.22, 0.2) * smoothstep(hw, 0.0, abs(edPx)) * (0.5 + 0.5 * on);
layer(acc, cover, lead, leadA * lerp(0.45, 1.0, on));
// Dust motes drifting in the light shafts, glinting as they turn.
float2 mq = px / (0.3 * u) + float2(time * 0.12, time * 0.2);
float2 mc = floor(mq);
float mh = hash2(mc + 41.0);
float2 mp = (mc + 0.2 + 0.6 * float2(hash2(mc + 3.0), hash2(mc + 8.0)) + 0.15 * sin(time * float2(0.7, 0.9) + mh * 30.0)) * 0.3 * u - float2(time * 0.12, time * 0.2) * 0.3 * u;
float glint = 0.5 + 0.5 * sin(time * 5.0 + mh * 40.0);
layer(acc, cover, float3(1.0, 0.96, 0.85), smoothstep(max(0.8, 0.025 * u), 0.0, length(px - mp)) * step(mh, 0.35) * saturate(shaft * 1.5) * glint * on);
// The rose window at the playhead: a sapphire disc, eight petals, twelve roundels and a golden boss.
float R = 0.47 * u;
float rl = max(0.6, 0.02 * u); // its finer tracery
float2 d = px - float2(head, 0.5 * u);
float rr = length(d);
float ang = atan2(d.y, d.x) + time * 0.25 + head / R * 0.15 + 0.15 * beat;
float s8 = (frac(ang / 0.7854) - 0.5) * 0.7854;
float2 p8 = float2(cos(s8), sin(s8)) * rr - float2(0.47 * R, 0.0);
float petal = (length(p8 / float2(0.29, 0.17)) - R) * 0.17;
float s12 = (frac(ang / 0.5236 + 0.5) - 0.5) * 0.5236;
float roundel = length(float2(cos(s12), sin(s12)) * rr - float2(0.84 * R, 0.0)) - 0.11 * R;
float boss = rr - 0.18 * R;
float disc = rr - R;
float3 rose = jewel(0.4) * 0.8;
rose = lerp(rose, frac(floor(ang / 0.7854) * 0.5) < 0.25 ? jewel(0.1) : jewel(0.6), step(petal, 0.0));
rose = lerp(rose, frac(floor(ang / 0.5236 + 0.5) * 0.5) < 0.25 ? jewel(0.75) : jewel(0.9), step(roundel, 0.0));
rose = lerp(rose, float3(1.0, 0.93, 0.7), step(boss, 0.0));
float glowIn = exp(-rr / R * 1.6);
rose = rose * (0.85 + 0.9 * glowIn) * (1.0 + 0.45 * beat) + float3(1.0, 0.9, 0.7) * glowIn * glowIn * 0.45;
float roseLead = min(min(abs(petal), abs(roundel)), abs(boss));
// The halo the rose throws, flaring on the beat, then the rose, its tracery and a gilded rim.
layer(acc, cover, lerp(colorC.rgb, float3(1.0, 0.95, 0.85), 0.5), exp(-max(disc, 0.0) / (0.3 * u)) * smoothstep(-aa, aa, disc) * (0.35 + 0.45 * beat));
layer(acc, cover, rose, smoothstep(aa, -aa, disc));
layer(acc, cover, float3(0.12, 0.11, 0.11), smoothstep(rl + aa, rl - aa, roseLead) * smoothstep(aa, -aa, disc));
layer(acc, cover, lerp(float3(0.8, 0.66, 0.42), colorC.rgb, 0.3), smoothstep(aa, -aa, abs(disc + hw * 0.5) - hw * 0.6));
return paint(acc / max(cover, 0.001), cover);
}