Hạ Long Bay

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

Thuyền buồm cánh dơi lướt tới chỗ đang phát giữa những đảo đá vôi chìm trong sương, mặt nước phẳng in bóng thuyền, phía sau là vệt sóng nhẹ, nước lấp lánh theo nhạc.

1 lượt tải Tải file, 10.1 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 d01dae6073face3f05c3fba0cc3b0f2e5f7da37ad12f07fd926ca5dc81e88ec6

//! name: Ha Long Bay
//! author: MusicBar
//! kind: progress
//! description: A junk with orange fan sails glides to the playhead between limestone karsts in layered mist, mirrored in calm water, leaving a gentle wake while the water glitters with the music.

float hash1(float n) { return frac(sin(n * 127.1 + 311.7) * 43758.5453); }
float hash2(float2 p) { return frac(sin(dot(p, float2(127.1, 311.7))) * 43758.5453); }
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);
}

// A row of limestone karsts: steep sided towers with rounded, ragged tops, one or none per cell.
float karst(float X, float cellW, float seed, float hMin, float hMax)
{
    float c = floor(X / cellW);
    float best = 0.0;
    for (int i = -1; i <= 1; i++)
    {
        float ci = c + i;
        float hh = hash1(ci * 7.3 + seed);
        float h = lerp(hMin, hMax, hh) * step(0.15, hash1(ci * 2.9 + seed));
        float dx = (X - (ci + 0.5 + 0.4 * (hash1(ci * 5.7 + seed) - 0.5)) * cellW) / (cellW * (0.13 + 0.17 * hash1(ci * 3.1 + seed)));
        float top = 0.86 + 0.14 * cos(dx * 3.5 + hh * 9.0);       // a lopsided, uneven crown
        best = max(best, h * top * pow(saturate(1.0 - pow(abs(dx), 4.0)), 0.3));
    }
    return best * (0.94 + 0.06 * vnoise(float2(X * 16.0, seed)));
}

// One sail: a fan of battened cloth opening up and back from the foot of its mast, scalloped between battens.
float2 fan(float2 p, float2 pivot, float R)
{
    float2 v = p - pivot;
    float r = length(v), t = (atan2(v.y, v.x + 0.0001) - 1.5) / 1.05;   // t: 0 along the mast, 1 at the back edge
    float k = frac(t * 6.0);
    float d = max(r - R * (0.93 + 0.07 * sin(3.1416 * k)), max(-t, t - 1.0) * r * 1.05);
    return float2(max(d, 0.05 - r), k);
}

// The junk in its own frame (bar heights, waterline at y = 0, bow to the right): color and coverage.
float4 junk(float2 b, float aa)
{
    float3 acc = float3(0, 0, 0);
    float cover = 0;
    float3 sailC = lerp(float3(0.95, 0.45, 0.14), colorA.rgb, 0.45);
    // Masts, then the three sails from the stern forward.
    float mast = min(min(abs(b.x + 0.33), abs(b.x - 0.03)), abs(b.x - 0.37)) - 0.012;
    mast = max(mast, b.y - (b.x < -0.15 ? 0.5 : (b.x < 0.2 ? 0.68 : 0.56)));
    layer(acc, cover, float3(0.18, 0.1, 0.06), smoothstep(aa, -aa, mast));
    float2 s0 = fan(b, float2(-0.33, 0.15), 0.38), s1 = fan(b, float2(0.03, 0.13), 0.56), s2 = fan(b, float2(0.37, 0.13), 0.46);
    float2 sl = s2.x < 0.0 ? s2 : (s1.x < 0.0 ? s1 : s0);
    float dS = min(min(s0.x, s1.x), s2.x);
    float3 sc = sailC * (0.75 + 0.25 * sin(3.1416 * sl.y)) * (0.7 + 0.5 * saturate(-sl.x / 0.15 + 0.2));
    sc = lerp(sc, sailC * 0.35, smoothstep(0.12, 0.0, min(sl.y, 1.0 - sl.y)) * 0.8);   // the dark battens
    layer(acc, cover, sailC * 0.25, smoothstep(aa, -aa, dS - aa * 1.4));
    layer(acc, cover, sc, smoothstep(aa, -aa, dS));
    // The hull: an upswept bow, a high stern, dark planks with a lighter rail; a cabin with warm lit windows.
    float ax = abs(b.x) / 0.62, bot = -0.035 + 0.15 * pow(ax, 3.0);
    float top = 0.11 + 0.06 * smoothstep(0.35, 0.62, b.x) + 0.1 * smoothstep(-0.3, -0.62, b.x);
    float dHull = max(max(b.y - top, bot - b.y), ax - 1.0);
    float3 hullC = lerp(float3(0.22, 0.12, 0.07), float3(0.45, 0.26, 0.13), saturate((b.y - bot) / 0.12)) * (0.85 + 0.15 * step(0.5, frac(b.y * 45.0)));
    hullC = lerp(hullC, lerp(float3(0.8, 0.55, 0.3), colorC.rgb, 0.3), smoothstep(0.012, 0.004, abs(b.y - top + 0.012)));
    float dCab = max(abs(b.x + 0.12) - 0.2, abs(b.y - 0.15) - 0.05);
    float win = step(0.5, frac((b.x + 0.12) * 18.0)) * step(abs(b.y - 0.155), 0.018) * step(abs(b.x + 0.12), 0.16);
    layer(acc, cover, float3(0.06, 0.03, 0.02), smoothstep(aa, -aa, min(dHull, dCab) - aa * 1.4));
    layer(acc, cover, lerp(float3(0.35, 0.2, 0.11), lerp(float3(1.0, 0.8, 0.45), colorC.rgb, 0.4) * 1.2, win), smoothstep(aa, -aa, dCab));
    layer(acc, cover, hullC, smoothstep(aa, -aa, dHull));
    // A pennant at the masthead, fluttering.
    float2 fq = b - float2(0.03, 0.66);
    float pen = max(max(abs(fq.y - 0.012 * sin(fq.x * 40.0 + time * 9.0)) - 0.022 * (1.0 + fq.x / 0.12), fq.x), -fq.x - 0.12);
    layer(acc, cover, colorC.rgb, smoothstep(aa, -aa, pen));
    return float4(acc, cover);
}

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 boat always floats upright
    float head = progress * size.x;
    float X = px.x / u, y = px.y / u, aa = 1.0 / u;
    float WL = 0.26, under = step(y, WL);                      // the waterline, and whether this pixel is below it
    float d = (px.x - head) / u;                               // bar heights ahead of the boat
    float seen = smoothstep(1.0, -0.6, d);                     // the mist has lifted where the boat has been
    float3 acc = float3(0, 0, 0);
    float cover = 0;

    // Sunset light low over the water where the boat has passed; the bay ahead is still cool and misty.
    float3 warm = lerp(float3(1.0, 0.62, 0.35), colorA.rgb, 0.35);
    layer(acc, cover, warm, exp(-abs(y - WL) / 0.22) * seen * (0.16 + 0.06 * level) * (1.0 - 0.5 * under));

    // Three rows of karsts from far to near, each paler with distance and fading into mist at its foot.
    float hF = karst(X + 0.3, 0.8, 11.0, 0.32, 0.68);
    float hM = karst(X, 1.3, 23.0, 0.28, 0.66);
    float hN = karst(X + 0.8, 2.1, 37.0, 0.25, 0.6);
    float rip = 0.012 * sin(X * 22.0 + time * 1.6 + y * 70.0) + 0.006 * sin(X * 57.0 - time * 2.3);
    float ky = lerp(y - WL, WL - y + rip, under);                // height above water, or its mirror below
    float fade = lerp(1.0, 0.45 * smoothstep(0.0, 0.03, WL - y) * (0.7 + 0.3 * vnoise(float2(X * 3.0, y * 60.0 - time))), under);
    float3 sky = lerp(float3(0.7, 0.8, 0.86), colorB.rgb, 0.3);
    float3 rock = lerp(float3(0.12, 0.2, 0.2), colorB.rgb * 0.3, 0.3);
    layer(acc, cover, lerp(sky * 0.95, sky * 0.7, smoothstep(0.0, 0.4, ky)), smoothstep(aa, -aa, ky - hF) * step(0.0, ky) * lerp(0.2, 0.45, seen) * fade);
    layer(acc, cover, lerp(sky * 0.8, lerp(sky, rock, 0.55), smoothstep(0.0, 0.35, ky)) + 0.25 * smoothstep(0.03, 0.0, hM - ky) * (1.0 - under), smoothstep(aa, -aa, ky - hM) * step(0.0, ky) * lerp(0.3, 0.7, seen) * fade);

    // A layer of mist lying on the water between the rows, thicker ahead of the boat.
    float mist = vnoise(float2(X * 0.8 - time * 0.07, y * 3.0)) * 0.6 + vnoise(float2(X * 2.3 - time * 0.12, y * 7.0)) * 0.4;
    layer(acc, cover, lerp(float3(0.92, 0.95, 0.97), colorB.rgb, 0.15), smoothstep(0.3, 0.8, mist) * exp(-pow((y - WL - 0.08) / 0.12, 2.0)) * lerp(0.5, 0.3, seen));

    // The near karsts: dark rock with green tops and a sky rim, misty at the foot.
    float veg = smoothstep(0.08, 0.0, hN - ky) * smoothstep(0.4, 0.7, vnoise(float2(X * 12.0, ky * 20.0)));
    float3 nearC = lerp(lerp(sky, rock, 0.7), rock * 0.75, smoothstep(0.0, 0.25, ky)) * (0.8 + 0.3 * vnoise(float2(X * 40.0, ky * 3.0)));
    nearC = lerp(nearC, lerp(float3(0.2, 0.38, 0.22), colorB.rgb * 0.5, 0.3), veg * 0.8);
    nearC += sky * 0.35 * smoothstep(0.025, 0.0, hN - ky) * (1.0 - under);
    layer(acc, cover, nearC, smoothstep(aa, -aa, ky - hN) * step(0.0, ky) * lerp(0.4, 0.92, seen) * fade);

    // Calm water: a faint tint, brighter streaks of reflected sky, and glitter that sparkles with the music.
    float wl = smoothstep(aa, -aa, abs(y - WL) - 0.006);
    layer(acc, cover, lerp(colorB.rgb * 0.35, float3(0.1, 0.2, 0.25), 0.4), under * smoothstep(0.0, 0.08, y) * lerp(0.12, 0.35, seen));
    layer(acc, cover, lerp(sky, float3(1, 1, 1), 0.4), wl * lerp(0.25, 0.6, seen));
    float2 gq = float2(X / 0.07, y / 0.035 - time * 0.3);
    float gh = hash2(floor(gq));
    float2 gf = (frac(gq) - 0.5) * float2(0.07, 0.035) * u;
    float spec = spectrum(frac(gh * 7.0) * 0.9);
    float twinkle = (0.5 + 0.5 * sin(time * (4.0 + 6.0 * gh) + gh * 40.0)) * spec * (0.6 + 0.8 * level) + beat * step(0.6, gh);
    float glint = exp(-abs(gf.x) / (0.03 * u) - abs(gf.y) / (0.006 * u)) + 0.5 * exp(-abs(gf.y) / (0.012 * u) - abs(gf.x) / (0.004 * u));
    layer(acc, cover, lerp(colorC.rgb, float3(1, 1, 1), 0.5), glint * twinkle * step(0.55, gh) * under * smoothstep(0.02, 0.06, y) * smoothstep(WL, WL - 0.03, y) * lerp(0.15, 1.0, seen) * exp(-max(-d - 1.0, 0.0) / 12.0));

    // The wake behind the boat: foam along the waterline and one arm of the V spreading toward us.
    float back = -d - 0.6;
    float foamN = vnoise(float2(X * 14.0 + time * 2.0, y * 40.0));
    float foam = smoothstep(0.008 + 0.014 * sqrt(max(back, 0.0)), 0.0, abs(y - WL + 0.008)) * smoothstep(0.3, 0.55, foamN);
    float arm = smoothstep(0.01, 0.0, abs(y - (WL - 0.015 - 0.07 * back))) * smoothstep(0.3, 0.55, foamN) * step(WL - 0.015 - 0.07 * back, WL);
    layer(acc, cover, float3(0.95, 0.98, 1.0), (foam + arm * 0.8) * smoothstep(-0.2, 0.3, back) * exp(-max(back, 0.0) / 3.0) * (0.8 + 0.4 * level));

    // The junk, rocking gently, and its reflection broken by the ripples.
    float2 b = float2(px.x - head, px.y) / u - float2(0.0, WL + 0.008 * sin(time * 1.3));
    float pitch = 0.03 * sin(time * 1.1) + 0.02 * beat;
    b = float2(b.x * cos(pitch) + b.y * sin(pitch), -b.x * sin(pitch) + b.y * cos(pitch));
    float2 rb = float2(px.x - head + rip * u * 0.8, (2.0 * WL - y) * u) / u - float2(0.0, WL + 0.02);
    float4 refl = junk(rb, aa);
    layer(acc, cover, refl.rgb * 0.55, refl.a * under * 0.6 * smoothstep(0.0, 0.1, y) * (0.7 + 0.3 * vnoise(float2(X * 4.0, y * 70.0 - time * 2.0))));
    layer(acc, cover, lerp(colorA.rgb, float3(1, 0.8, 0.5), 0.3), exp(-length((b - float2(0.0, 0.35)) / float2(1.4, 1.0)) / 0.3) * (0.12 + 0.12 * level + 0.15 * beat));
    float4 boat = junk(b, aa);
    layer(acc, cover, boat.rgb, boat.a);

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