Blue Comet

by K-Kein, progress bar

Sao chổi xanh bay ngang thành phố đêm.

39 downloads Download file, 7.9 KB
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 6d976539a56a253a89d9a11e291e54efe398b26c684ff4ffe364ef745dfb981a

//! name: Blue Comet City
//! kind: progress
//! description: Sao chổi xanh dương bay qua bầu trời đêm thành phố, đầu sao chạy theo tiến trình bài hát

// Lưu ý: skin này chưa được biên dịch thử. Nếu MusicBar báo lỗi, hãy dán nguyên dòng lỗi lại để sửa.

// Hàm băm không dùng sin, nên cho kết quả giống nhau trên mọi bộ vẽ
float hash12(float2 p)
{
    float3 p3 = frac(float3(p.x, p.y, p.x) * 0.1031);
    p3 += dot(p3, p3.yzx + 33.33);
    return frac((p3.x + p3.y) * p3.z);
}

// Đường bay của sao chổi: x từ 0 đến 1, trả về uv.y (võng nhẹ lên xuống)
float cometPath(float x)
{
    return 0.40 + 0.07 * sin(x * 7.0 + 0.8);
}

// Một lớp sao theo lưới ô vuông. Mỗi ô có thể chứa một ngôi sao lấp lánh
float starField(float2 p, float cell, float density, float radius, float spike, float seed, float tm)
{
    float2 q = p / cell;
    float2 id = floor(q);
    float2 f = frac(q);
    float h = hash12(id + seed);
    float2 pos = float2(hash12(id + seed + 11.7), hash12(id + seed + 23.1)) * 0.7 + 0.15;
    float2 dv = (f - pos) * cell;
    float core = exp(-dot(dv, dv) / (radius * radius));
    float spikes = spike * (exp(-abs(dv.y) * 2.2 - abs(dv.x) * 0.4) + exp(-abs(dv.x) * 2.2 - abs(dv.y) * 0.4));
    float on = step(1.0 - density, h);
    float tw = 0.6 + 0.4 * sin(tm * (1.0 + 2.5 * h) + h * 61.0);
    float amp = 0.45 + 0.55 * hash12(id + seed + 5.3);
    return on * (core + spikes) * tw * amp;
}

// Chiều cao đường chân trời (pixel): ghép hai lưới tòa nhà rộng hẹp khác nhau, thêm ăng-ten
float skylineHeight(float x, float wA, float wB, float maxH, float seed, float u)
{
    float ia = floor(x / wA);
    float ib = floor(x / wB);
    float ha = floor(hash12(float2(ia, seed)) * 6.0) / 6.0;
    float hb = floor(hash12(float2(ib, seed + 7.0)) * 6.0) / 6.0;
    float roof = max(ha * 0.55, hb) * maxH;
    float xl = x - (ib + 0.5) * wB;
    float ant = step(0.8, hash12(float2(ib, seed + 3.0))) * step(0.5, hb);
    float spire = ant * step(abs(xl), 0.8) * (hb * maxH + 5.0 * u);
    return max(roof, spire);
}

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float s = size.y / 40.0;                       // hệ số theo độ cao thanh
    float2 px = uv * size;                         // tọa độ pixel
    float gy = size.y - px.y;                      // độ cao tính từ đáy thanh

    // ---------- Đầu sao chổi chạy theo progress ----------
    float headU = lerp(0.015, 0.985, saturate(progress));
    float2 head = float2(headU * size.x, cometPath(headU) * size.y);
    float dxs = px.x - head.x;                     // âm: phía sau đầu (đuôi)
    float behind = max(-dxs, 0.0);
    float played = smoothstep(-36.0 * s, 36.0 * s, -dxs);
    float2 hv = float2(dxs, px.y - head.y);
    float dh = length(hv);
    float gain = lerp(0.6, 1.0, playing);          // tạm dừng thì mờ bớt
    float pulse = 1.0 + 0.4 * beat;                // nhịp trống làm đầu sao bừng lên

    // ---------- Bầu trời đêm ----------
    float tv = saturate(gy / size.y);
    float3 skyTop = float3(0.000, 0.006, 0.030);
    float3 skyLow = float3(0.016, 0.058, 0.170);
    float3 sky = lerp(skyLow, skyTop, smoothstep(0.0, 1.0, tv));
    sky *= 0.75 + 0.25 * sin(px.x * 0.004 + 1.3);  // ánh đèn thành phố không đều
    sky *= 0.55 + 0.9 * played;                    // phần đã phát sáng hơn phần chưa phát
    sky += float3(0.04, 0.13, 0.38) * exp(-dh / (55.0 * s)) * 0.6 * pulse * gain;

    // ---------- Các ngôi sao (chút trắng) ----------
    float horizonFade = smoothstep(0.12, 0.55, tv);
    float starGain = lerp(0.45, 1.0, played) * horizonFade;
    float2 sp = float2(px.x, gy);
    float st = starField(sp, 9.0, 0.11, 0.75, 0.0, 1.0, time)
             + starField(sp, 31.0, 0.40, 1.0, 0.5, 5.0, time);
    float3 col = sky + float3(0.80, 0.90, 1.0) * st * starGain;

    // ---------- Đuôi sao chổi ----------
    float cy = cometPath(uv.x) * size.y;
    float oy = px.y - cy;
    float tailLen = clamp(size.x * 0.2, 220.0, 420.0) * (0.9 + 0.25 * level + 0.1 * beat);
    float t = behind / tailLen;
    float ramp = smoothstep(-1.0 * s, 3.0 * s, -dxs);

    // đuôi ion: mảnh, thẳng, sáng
    float w1 = s * (0.8 + 1.8 * t);
    float ion = exp(-(oy * oy) / (w1 * w1)) * exp(-t * 3.2);

    // đuôi bụi: rộng, cong lên, có vệt chảy ra sau
    float oyd = oy + s * 6.0 * t * t;
    float w2 = s * (1.8 + 7.0 * t);
    float streak = 0.72 + 0.28 * sin(oyd * 1.4 / s + behind * 0.045 - time * 3.5);
    float dust = exp(-(oyd * oyd) / (w2 * w2)) * exp(-t * 2.4) * streak;

    // hai tia phụ tỏa ra như lông vũ
    float w3 = s * (0.6 + 1.0 * t);
    float o3a = oy - s * (1.2 + 6.0 * t);
    float o3b = oy + s * (1.2 + 6.0 * t);
    float fan = (exp(-(o3a * o3a) / (w3 * w3)) + exp(-(o3b * o3b) / (w3 * w3))) * exp(-t * 4.5);

    float3 ionCol = lerp(float3(0.20, 0.55, 1.00), float3(0.80, 0.93, 1.00), exp(-t * 6.0));
    float3 dustCol = lerp(float3(0.03, 0.22, 0.95), float3(0.15, 0.50, 1.00), exp(-t * 2.0));
    float3 tailLight = ionCol * ion + dustCol * dust * 0.75 + float3(0.12, 0.40, 1.0) * fan * 0.45;
    tailLight *= ramp * gain * (0.9 + 0.3 * level);

    // hạt bụi lấp lánh nằm trong đuôi
    float2 pc = px / 6.0;
    float2 pid = floor(pc);
    float2 pfr = frac(pc);
    float ph = hash12(pid + 71.0);
    float2 ppos = float2(hash12(pid + 13.0), hash12(pid + 29.0)) * 0.6 + 0.2;
    float pd = length((pfr - ppos) * 6.0);
    float spark = exp(-pd * pd / 0.5) * step(0.7, ph) * (0.5 + 0.5 * sin(time * 6.0 + ph * 90.0));
    float density = (dust + ion * 0.7) * ramp;
    tailLight += float3(0.65, 0.85, 1.0) * spark * density * 1.4 * gain;

    // ---------- Đầu sao chổi: nhân, tóc sao, quầng ----------
    float r0 = 2.4 * s;
    float nucleus = 1.0 - smoothstep(r0 * 0.3, r0 * 0.95, dh);
    float coma = exp(-dh / (r0 * 1.7));
    float halo = exp(-dh / (r0 * 6.0));
    float3 headLight = float3(0.30, 0.65, 1.0) * coma * 0.85 + float3(0.05, 0.25, 0.95) * halo * 0.35;
    headLight *= pulse * gain;

    col += tailLight + headLight;
    // quầng cộng quanh nhân, nhân thì thay màu (không cộng đè) để không bị cháy trắng
    col = lerp(col, float3(0.88, 0.95, 1.0), nucleus * gain);

    // ---------- Thành phố: lớp xa ----------
    float comet2 = exp(-abs(dxs) / (80.0 * s)) * (0.6 + 0.8 * beat) * gain;
    float farH = max(skylineHeight(px.x, 17.0, 41.0, 0.44 * size.y, 40.0, s), 2.5 * s);
    float farMask = saturate(farH - gy + 0.5);
    float farRim = 1.0 - smoothstep(0.2, 1.8 * s, farH - gy);
    float3 farCol = float3(0.014, 0.038, 0.100) + float3(0.02, 0.06, 0.16) * exp(-gy / (5.0 * s));
    farCol += float3(0.10, 0.34, 0.95) * farRim * comet2 * 0.6;
    col = lerp(col, farCol, farMask);

    // ---------- Thành phố: lớp gần (gần như đen, có vài ô cửa sổ) ----------
    float nearH = max(skylineHeight(px.x, 13.0, 31.0, 0.30 * size.y, 0.0, s), 1.5 * s);
    float nearMask = saturate(nearH - gy + 0.5);
    float nearRim = 1.0 - smoothstep(0.2, 1.6 * s, nearH - gy);
    float3 nearCol = float3(0.003, 0.006, 0.018) + float3(0.10, 0.34, 0.95) * nearRim * comet2 * 0.9;
    col = lerp(col, nearCol, nearMask);

    float2 wc = float2(px.x, gy) / 5.0;
    float2 wid = floor(wc);
    float2 wf = frac(wc);
    float lampOn = step(0.78, hash12(wid + 91.0));
    float lampShape = step(0.25, wf.x) * step(wf.x, 0.75) * step(0.25, wf.y) * step(wf.y, 0.75);
    float lampBlink = 0.7 + 0.3 * sin(time * 0.8 + hash12(wid + 3.0) * 80.0);
    float lampBody = step(gy, nearH - 2.0 * s) * step(1.5 * s, gy);
    float lamp = lampOn * lampShape * lampBlink * lampBody * nearMask;
    col += float3(0.55, 0.78, 1.0) * lamp * 0.32 * (0.6 + 0.4 * played);

    // ---------- Kết quả ----------
    col = saturate(col);
    float a = 0.92 + 0.08 * saturate(max(col.r, max(col.g, col.b)) * 3.0);
    return paint(col, a);
}