Plasma Blade

của MusicBar, thanh tiến trình

Cán kiếm kim loại ở đầu thanh phóng ra lưỡi năng lượng dài tới chỗ đang phát, lưỡi kiếm ù ù phập phồng theo nhạc, tới nhịp là mũi kiếm tóe tia lửa.

9 lượt tải Tải file, 5.9 KB
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 b15b979112ef729df798fcc3e484385562810e998ec1deee10ebcd57d57cf507

//! name: Plasma Blade
//! author: MusicBar
//! kind: progress
//! description: A machined hilt at the start of the bar ignites a humming energy blade that reaches to the playhead, swells with the music and spits sparks from its tip on every beat.

// A steady random number for a cell.
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);
}

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);
}

// Polished metal across a cylinder: t runs -1 (bottom) to 1 (top); a sharp sky highlight, a dark band, a warm floor bounce.
float3 metal(float t, float3 tint)
{
    float n = sqrt(saturate(1.0 - t * t));
    float3 c = lerp(float3(0.16, 0.17, 0.2), float3(0.62, 0.64, 0.68), n) * tint;
    c += float3(1, 1, 1) * 0.75 * smoothstep(0.2, 0.0, abs(t - 0.5));
    c *= 1.0 - 0.45 * smoothstep(0.18, 0.0, abs(t + 0.15));
    return c + colorA.rgb * 0.25 * smoothstep(-0.6, -1.0, t);
}

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float H = size.y;
    float2 px = float2(uv.x * size.x, rise(uv) * size.y);   // pixels: along the bar, up from the screen edge
    float yc = H * 0.5;
    float dy = px.y - yc;
    float head = max(progress * size.x, 3.4 * H);

    float3 acc = float3(0, 0, 0);
    float cover = 0;

    // A faint guide for the rest of the song.
    float guide = step(head + 0.4 * H, px.x) * step(frac(px.x / (0.25 * H)), 0.4) * smoothstep(1.0, 0.0, abs(dy));
    layer(acc, cover, colorB.rgb, guide * 0.18);

    // The blade: a white-hot core in a colored glow whose width follows the spectrum along its length.
    float x1 = 3.2 * H;
    float along = saturate((px.x - x1) / max(head - x1, 1.0));
    float sv = spectrum(along * 0.85);
    float hum = 0.9 + 0.06 * sin(time * 95.0) + 0.04 * sin(time * 31.0 + px.x * 0.02);
    float shimmer = 0.014 * H * sin(px.x / H * 5.3 - time * 17.0) * sin(px.x / H * 2.3 + time * 6.1);
    float dx = max(x1 - px.x, 0.0) + max(px.x - head, 0.0);
    float db = length(float2(dx, dy));
    float dh = length(float2(dx, max(abs(dy) + shimmer, 0.0)));          // the glow's edge wavers in the heat
    float wide = 0.12 * H * (0.8 + 0.5 * sv + 0.3 * level + 0.5 * beat);
    float rc = 0.07 * H * (1.0 + 0.25 * beat);
    float pulse = pow(0.5 + 0.5 * sin(px.x / H * 1.6 - time * 9.0), 10.0) * 0.2;
    layer(acc, cover, colorA.rgb, exp(-dh / (wide * 2.4)) * 0.28 * hum);
    layer(acc, cover, lerp(colorA.rgb, float3(1, 1, 1), 0.2), exp(-dh / wide) * (0.8 + pulse) * hum);
    layer(acc, cover, lerp(colorA.rgb, float3(1, 1, 1), 0.6), smoothstep(rc * 1.7 + 0.6, rc * 1.7 - 0.6, db) * 0.7 * hum);
    layer(acc, cover, lerp(float3(1, 1, 1), colorA.rgb, 0.08), smoothstep(rc + 0.6, rc - 0.6, db) * hum);

    // The tip: a bright knot with a flare line that stretches on the beat.
    float2 tp = px - float2(head, yc);
    float knot = exp(-length(tp) / (0.1 * H * (1.0 + 0.8 * beat)));
    float flareLine = exp(-abs(tp.y) / (0.018 * H + 0.3)) * exp(-abs(tp.x) / (H * (0.3 + 1.2 * beat))) * (0.3 + 0.7 * beat);
    layer(acc, cover, lerp(colorA.rgb, float3(1, 1, 1), 0.7), knot + flareLine);

    // Sparks spat forward from the tip, many on the beat, falling as they fly.
    float a = atan2(tp.y, tp.x);
    float b = floor((a + 3.14159) / 6.28318 * 14.0);
    float hb = hash2(float2(b, 7.0));
    float age = frac(time * 2.4 + hb) * 0.42;
    float ang = (b + 0.2 + 0.6 * hash2(float2(b, floor(time * 2.4 + hb)))) / 14.0 * 6.28318 - 3.14159;
    float vel = H * (2.2 + 2.0 * hb);
    float2 e1 = float2(cos(ang), sin(ang)) * vel * age - float2(0, 2.6 * H * age * age);
    float2 e0 = float2(cos(ang), sin(ang)) * vel * max(age - 0.05, 0.0) - float2(0, 2.6 * H * max(age - 0.05, 0.0) * max(age - 0.05, 0.0));
    float2 pa = tp - e0;
    float2 ba = e1 - e0;
    float hh = saturate(dot(pa, ba) / max(dot(ba, ba), 0.001));
    float sw = max(0.6, 0.02 * H);
    float ds = length(pa - ba * hh);
    float lit = smoothstep(-0.2, 0.3, cos(ang)) * smoothstep(0.42, 0.1, age) * saturate(0.2 + 0.4 * level + 1.6 * beat);
    layer(acc, cover, colorA.rgb, exp(-ds / (sw * 2.5)) * hh * 0.5 * lit);
    layer(acc, cover, lerp(colorA.rgb, float3(1, 1, 1), 0.3 + 0.7 * hh), smoothstep(sw + 0.6, sw - 0.4, ds) * (0.3 + 0.7 * hh) * lit);

    // The hilt: pommel, ribbed grip, collar with a button light, and a flared emitter.
    float x0 = 0.3 * H;
    float u = (px.x - x0) / H;
    float r = 0.17;
    r = lerp(r, 0.15, step(0.38, u));
    r = lerp(r, 0.19, step(1.95, u));
    r = lerp(r, 0.16, step(2.25, u));
    r = lerp(r, 0.17 + 0.07 * saturate((u - 2.3) / 0.6), step(2.3, u));
    float fr = frac((u - 0.4) / 0.17);
    float ribs = step(0.4, u) * step(u, 1.92) * step(0.4, fr);
    float bulge = sin(saturate((fr - 0.4) / 0.6) * 3.14159) * ribs;
    r += 0.02 * bulge - 0.06 * smoothstep(0.12, 0.0, u) - 0.06 * smoothstep(2.78, 2.9, u);
    r *= H;
    float inside = smoothstep(r + 0.5, r - 0.5, abs(dy)) * step(0.0, u) * step(u, 2.9);
    float t = dy / max(r, 1.0);
    float3 hilt = metal(t, float3(1.0, 1.0, 1.0));
    hilt = lerp(hilt, metal(t, float3(0.3, 0.3, 0.34)) * (0.55 + 0.6 * bulge), ribs);
    hilt = lerp(hilt, metal(t, float3(0.55, 0.5, 0.45)), step(u, 0.38));
    float vent = step(2.42, u) * step(u, 2.8) * step(0.5, frac(u / 0.11)) * step(abs(t), 0.35);
    hilt *= 1.0 - 0.75 * vent;
    hilt += colorA.rgb * 0.5 * vent * (0.6 + 0.4 * hum);
    hilt *= 1.0 - 0.45 * smoothstep(r - 1.6, r - 0.2, abs(dy));
    layer(acc, cover, hilt, inside);
    float btn = length(px - float2(x0 + 2.1 * H, yc + 0.05 * H));
    float blink = 0.75 + 0.25 * sin(time * 3.0) + 0.3 * beat;
    layer(acc, cover, colorC.rgb, exp(-btn / (0.06 * H)) * 0.6 * blink);
    layer(acc, cover, lerp(colorC.rgb, float3(1, 1, 1), 0.4), smoothstep(0.055 * H + 0.5, 0.055 * H - 0.5, btn) * blink);

    return paint(acc / max(cover, 0.001), cover);
}