Bullet Bloom
của MusicBar, visualizer
Mưa đạn kiểu bullet hell nở hoa dọc thanh, đạn sáng lõi trắng xoáy ra từ mấy tâm bắn đang quay, nhạc càng to đạn càng dày càng nhanh, tới nhịp là bung thêm một vòng đạn to.
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 59cb79266978cb2ae7da2dbf6d592240561845171beea95af5187f9e87f12765
//! name: Bullet Bloom
//! author: MusicBar
//! kind: visualizer
//! description: Bullet-hell patterns bloom along the bar: glowing white-cored bullets pour out of a row of spinning emitters in spirals and rings, faster and denser as the music gets loud, with a big ring fired on every beat.
float hash1(float n) { return frac(sin(n * 91.3458 + 47.123) * 43758.5453); }
float2 rot2(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); }
// 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 glowing bullet: a soft halo, a thin dark rim (so it holds on a light taskbar), the colored shell and a white-hot core.
// d is the distance to its edge and depth runs 0 at the edge to 1 at the center, both in bar heights.
void bullet(inout float3 acc, inout float cover, float d, float depth, float3 col, float a, float u)
{
layer(acc, cover, col, exp(-max(d, 0.0) / 0.065) * 0.42 * a);
layer(acc, cover, col * 0.3, smoothstep(0.5, -0.5, d * u - 1.0) * a);
layer(acc, cover, lerp(col, float3(1, 1, 1), smoothstep(0.3, 0.65, depth)), smoothstep(0.5, -0.5, d * u) * a);
}
// One rice bullet of the spiral stream, the one fired at time ti on the arm nearest the pixel's angle a.
// Returns its edge distance, its depth and whether its arm is firing (the odd arms join in when the song is loud).
float3 rice(float2 q, float a, float ti, float vs, float dir, float k)
{
float th = dir * 2.1 * ti + k * 1.3;
float ai = floor((a - th) * 6.0 / 6.28318 + 0.5);
float sa = th + ai * 6.28318 / 6.0;
float2 e = float2(cos(sa), sin(sa));
float2 rel = q - (0.12 + vs * (time - ti)) * e;
float2 loc = float2(dot(rel, e), dot(rel, float2(-e.y, e.x)));
float gate = lerp(1.0, smoothstep(0.3, 0.6, level), abs(frac(ai * 0.5)) * 2.0) * step(0.0, time - ti);
return float3(ellipse(loc, float2(0.085, 0.04)), 1.0 - length(loc / float2(0.085, 0.04)), gate);
}
// Everything one emitter has fired, seen from pixel p (in bar heights). k numbers the emitter, sp is its spectrum band.
void emitter(inout float3 acc, inout float cover, float2 p, float k, float sp, float u)
{
float2 c = float2((k + 0.5) * 4.6 + 0.35 * sin(time * 0.4 + k * 2.3), 0.5 + 0.05 * sin(time * 1.1 + k * 1.7));
float2 q = p - c;
float r = length(q);
float a = atan2(q.y, q.x);
float dir = hash1(k) < 0.5 ? -1.0 : 1.0;
float odd = abs(frac(k * 0.5)) * 2.0;
float3 cMain = lerp(colorA.rgb, colorB.rgb, odd);
float3 cAlt = lerp(colorB.rgb, colorA.rgb, odd);
float fade = smoothstep(4.1, 2.6, r); // bullets die out before they reach the next emitter's ground
// The sigil: two counter-turning squares inside a ring, faint, behind everything it fires.
float2 s1 = rot2(q, time * 0.9 * dir), s2 = rot2(q, -time * 0.9 * dir + 0.785);
float sig = min(abs(max(abs(s1.x), abs(s1.y)) - 0.21), abs(max(abs(s2.x), abs(s2.y)) - 0.21));
sig = min(sig, abs(r - 0.36));
layer(acc, cover, cMain, smoothstep(1.1, 0.0, sig * u) * (0.45 + 0.4 * beat));
// The beat ring: a dozen big accent orbs thrown out fast on every beat.
float Rb = 0.25 + (1.0 - beat) * 2.6;
float rb = k * 0.7 + time * 0.3 * dir;
float ab = rb + floor((a - rb) * 12.0 / 6.28318 + 0.5) * 6.28318 / 12.0;
float db = length(q - Rb * float2(cos(ab), sin(ab)));
bullet(acc, cover, db - 0.12, 1.0 - db / 0.12, colorC.rgb, smoothstep(0.02, 0.3, beat) * fade, u);
// Rings: every 0.55 s a circle of 20 orbs, each ring half a step round from the last and slowly turning as it flies.
float T = 0.55, v = 1.3 + 1.5 * level, ph = time / T;
float j = clamp(floor((r - 0.15) / (v * T) - frac(ph) + 0.5), 0.0, 9.0);
float age = (frac(ph) + j) * T;
float R = 0.15 + v * age;
float rr = floor(ph) - j;
float rot = rr * 3.14159 / 20.0 + age * 0.35 * dir;
float ang = rot + floor((a - rot) * 20.0 / 6.28318 + 0.5) * 6.28318 / 20.0;
float dc = length(q - R * float2(cos(ang), sin(ang)));
float orb = 0.065 + 0.035 * sp;
bullet(acc, cover, dc - orb, 1.0 - dc / orb, cAlt, fade * smoothstep(0.0, 0.12, age), u);
// Spirals: a stream of rice bullets fired every 0.09 s from a turning muzzle; three arms, six when the song is loud.
// The pixel checks the two shots that bracket its radius, so no glow is cut off between them.
float vs = 1.9 + 1.6 * level;
float t0 = floor((time - max(r - 0.12, 0.0) / vs) / 0.09) * 0.09;
float3 b0 = rice(q, a, t0, vs, dir, k);
float3 b1 = rice(q, a, t0 + 0.09, vs, dir, k);
bullet(acc, cover, b0.x, b0.y, cMain, b0.z * fade, u);
bullet(acc, cover, b1.x, b1.y, cMain, b1.z * fade, u);
// The core: a hot white heart that swells with its band and flares on the beat.
float rc = 0.08 + 0.05 * sp + 0.05 * beat;
layer(acc, cover, cMain, exp(-max(r - rc, 0.0) / 0.13) * (0.55 + 0.35 * beat));
layer(acc, cover, lerp(cMain, float3(1, 1, 1), smoothstep(rc, rc * 0.3, r)), smoothstep(0.5, -0.5, (r - rc) * u));
}
float4 main(float2 uv : TEXCOORD) : COLOR
{
float u = size.y;
float2 p = float2(uv.x * size.x, (1.0 - uv.y) * size.y) / u; // bar heights, screen-up
float3 acc = float3(0, 0, 0);
float cover = 0;
// Emitters stand every 4.6 bar heights; a pixel sees its own emitter and the nearer neighbor.
float k0 = floor(p.x / 4.6);
float k1 = k0 + (frac(p.x / 4.6) < 0.5 ? -1.0 : 1.0);
float span = size.x / u;
float sp0 = spectrum(abs((k0 + 0.5) * 4.6 / span - 0.5) * 2.0);
float sp1 = spectrum(abs((k1 + 0.5) * 4.6 / span - 0.5) * 2.0);
emitter(acc, cover, p, k1, sp1, u);
emitter(acc, cover, p, k0, sp0, u);
return paint(acc / max(cover, 0.001), cover);
}