Girl on Cloud

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

Cô bé cưỡi chổi bay ngang biển mây theo bài hát: đầu bài ở mép trái, hết bài là tới mép phải. Trời tự xoay vòng, bình minh hồng, trưa trong veo, hoàng hôn rồi đêm trăng sao; thỉnh thoảng mây kéo tới, mưa rơi, tạnh thì cầu vồng hiện. Mây tích vươn lên khỏi taskbar, cô bé bay khuất sau rồi lại ló ra. Hình động cô bé của Xandercorp trên LottieFiles.

Cần MusicBar 2.0.2 trở lên: skin này dùng thứ bản cũ chưa có (vẽ tràn lên trên taskbar, hình động đi kèm). Bản cũ hơn không thấy nó trong kho, cập nhật app là có.

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 686f9cf6173bd4c56a5f582657aff63a56baa5c64f738efe6545f779fdd2fc45

//! name: Girl on Cloud
//! author: MusicBar
//! kind: progress
//! description: Cô bé cưỡi chổi bay theo bài trên biển mây, trời tự xoay ngày đêm, nắng mưa rồi cầu vồng
//! headroom: 84
//! bloom: 0.22 0.86
//! layer: girl.lottie back follow=progress y=24 size=68 flip=x bob=3,3.1 sway=2,4.3

// A sea of clouds seen from above, painted like the background of an animated film: cumulus with flat, shadowed bodies
// and bright tops, three planned values, a blue-violet shadow, the far rows taking the colour of the air; cumulus
// towers rise above the taskbar.
// The girl on her broom is the song's progress (the skin's layer, behind: the towers hide her as she passes; her shadow
// falls on the clouds below, read from the layer). The sky keeps its own time: a day every four minutes (dawn, day,
// golden hour, dusk, a moonlit night with stars) and, out of step with it, weather every seven (clear, clouding over
// with towers growing, rain, clearing with a rainbow by day).
// Animation of the girl: by Xandercorp on LottieFiles (Lottie Simple License).
// Hash without Sine by Dave Hoskins (MIT).

// Seconds added to the sky's clocks (for looking at another hour or weather; 0 in use).
#define DAYSHIFT 0.0
#define WXSHIFT 0.0

float hash11(float p) { p = frac(p * 0.1031); p *= p + 33.33; p *= p + p; return frac(p); }
float hash12(float2 p) { float3 q = frac(p.xyx * 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);
    float2 u = f * f * (3.0 - 2.0 * f);
    return lerp(lerp(hash12(i), hash12(i + float2(1, 0)), u.x), lerp(hash12(i + float2(0, 1)), hash12(i + 1.0), u.x), u.y);
}
float3 hexColor(float h) { return float3(floor(h / 65536.0), floor(frac(h / 65536.0) * 256.0), frac(h / 256.0) * 256.0) / 255.0; }
float3 softWhite(float3 c, float k) { float m = max(c.r, max(c.g, c.b)); return lerp(c / max(m, 1.0), float3(1, 1, 1), k * saturate(m - 1.0)); }
float luma(float3 c) { return dot(c, float3(0.299, 0.587, 0.114)); }
float2 rareEvent(float period, float len, float seed)
{
    float n = floor(time / period);
    float start = hash11(n + seed) * (period - len);
    float t = time - n * period - start;
    return float2(step(0.0, t) * step(t, len), t);
}

// The sky's own clock: where in the day (0 dawn, 0.13 to 0.38 day, 0.48 golden hour, 0.56 dusk, 0.66 to 0.9 night),
// and the weather (0 clear, 1 overcast; rain; a rainbow after it).
static float PHASE, NIGHT, OVERCAST, RAIN, RAINBOW;
static float3 LIT, MID, SHADE, DEEP, AIR, SKY, SUNC;
static float LIGHTX, BAR, WIDTH, RIMK;

float3 dayColor(float dawn, float day, float gold, float dusk, float night)
{
    float p = PHASE;
    float3 c = hexColor(dawn);
    c = lerp(c, hexColor(day), smoothstep(0.03, 0.13, p));
    c = lerp(c, hexColor(gold), smoothstep(0.38, 0.48, p));
    c = lerp(c, hexColor(dusk), smoothstep(0.48, 0.56, p));
    c = lerp(c, hexColor(night), smoothstep(0.56, 0.66, p));
    c = lerp(c, hexColor(dawn), smoothstep(0.9, 0.99, p));
    return c;
}

// Lays a colour with its own coverage over what is there (the skin paints with straight alpha), so a half-covering
// light thing stays light instead of being mixed with the dark sky and then made see-through as well.
void over(inout float3 col, inout float alpha, float3 c, float a)
{
    float na = a + alpha * (1.0 - a);
    col = (c * a + col * alpha * (1.0 - a)) / max(na, 0.0001);
    alpha = na;
}

// Clouded over: the colours go grey-blue and darker.
float3 weather(float3 c, float dim)
{
    return lerp(c, luma(c) * float3(0.84, 0.88, 0.97) * dim, OVERCAST * 0.7);
}

// One painted cumulus surface: n its normal (facing us is +z), edge how near its rim, low 0 at its base to 1 well up.
float4 shadeCloud(float3 n, float edge, float low, float2 P, float fog)
{
    // Key light from high up, turning towards the sun (or the moon) for clouds near it: tops lit, the rest in shadow.
    float lx = clamp((LIGHTX - P.x) / (0.35 * WIDTH), -1.0, 1.0) * 0.6;
    float3 L = normalize(float3(lx - 0.35, 0.9, 0.12));
    // The turn from light to shadow wavers a little, as a brush would leave it.
    float ndl = dot(n, L) + (vnoise(P * float2(0.11, 0.2)) - 0.5) * 0.16;
    // Three painted values with soft cel edges: deep shadow, shadow, light (and a mid tone at the turn).
    float3 c = lerp(DEEP, SHADE, smoothstep(-0.4, -0.1, ndl));
    c = lerp(c, MID, smoothstep(0.02, 0.2, ndl));
    c = lerp(c, LIT, smoothstep(0.26, 0.45, ndl));
    // Lower in the cloud is darker (the puffs above shade it).
    c = lerp(lerp(DEEP, SHADE, 0.45), c, 0.45 + 0.55 * low);
    // Silver lining: the thin edge of a puff against a low sun, strongest near it.
    float2 toSun = normalize(float2(LIGHTX - P.x, 60.0));
    float near = exp(-abs(P.x - LIGHTX) / (0.28 * WIDTH));
    float rim = edge * edge * edge * saturate(dot(normalize(n.xy + 1e-4), toSun)) * near * RIMK;
    c += SUNC * rim * 1.6;
    // A painter's wet edge: a touch of texture inside the shapes, never noise on the silhouette.
    c *= 0.96 + 0.08 * vnoise(P * float2(0.09, 0.16));
    return float4(lerp(c, AIR, fog), 1.0);
}

// Puffs as spherical caps melted together: their heights blended by a soft maximum (weights exp(6 z / r)), so where two
// meet there is a soft crease, not a seam. Feed each puff with addPuff, then read the surface with puffNormal.
static float PW, PZ;
static float2 PG;
static float PCOVER;
void puffsBegin() { PW = 0.0; PZ = 0.0; PG = float2(0, 0); PCOVER = 0.0; }
// squash: how much flatter than round it looks (far clouds, seen at a slant, are flatter); lump: how knobbly its outline is.
void addPuff(float2 P, float2 cen, float rr, float lift, float squash, float lump)
{
    float2 d = P - cen;
    d.y *= squash;
    // A knobbly outline: the radius wanders a little around the puff (a cauliflower, not a coin).
    float rl = rr * (1.0 + lump * (vnoise(P / (rr * 0.28) + cen * 0.37) - 0.5));
    float q = rl * rl - dot(d, d);
    PCOVER = max(PCOVER, saturate(rl - length(d) + 0.5));
    if (q <= 0.0) return;
    float z = sqrt(q);
    float w = exp(clamp(6.0 * z / rl + lift, -30.0, 30.0));
    PW += w;
    PZ += (z / rl) * w;
    PG += (-d / max(z, rl * 0.08)) * w;
}
float3 puffNormal(out float edge)
{
    if (PW <= 0.0) { edge = 0.0; return float3(0, 0, 1); }
    float2 g = PG / PW;
    edge = 1.0 - saturate(PZ / PW);
    return normalize(float3(-g, 1.0));
}

// A row of cloud tops along a rolling baseline (DIPs from the screen's edge), gathering into banks and thinning out.
float4 cloudRow(float2 P, float base, float r, float drift, float seed, float fog, float squash)
{
    float cw = r * 1.45;
    float x = P.x + drift;
    float ci = floor(x / cw);
    base += r * 0.5 * (vnoise(float2(x / (cw * 5.0), seed)) - 0.5);
    puffsBegin();
    for (int k = -1; k <= 1; k++)
    {
        float c = ci + k;
        float h1 = hash11(c * 13.71 + seed), h2 = hash11(c * 7.31 + seed * 3.1);
        float bank = vnoise(float2(c / 7.0, seed * 1.7));
        float rr = r * (0.5 + 0.7 * h1) * lerp(0.45, 1.25, bank);
        addPuff(P, float2((c + 0.2 + 0.6 * h2) * cw - drift, base + rr * (0.05 + 0.3 * h2) / squash), rr, 0.0, squash, 0.22);
    }
    float cover = PCOVER;
    float edge;
    float3 n = puffNormal(edge);
    // The body under the tops: the side of the row facing us, in the puffs' shadow, darker the deeper it goes.
    float body = saturate(base - P.y + 0.5);
    if (PW <= 0.0 && body > 0.0)
    {
        float deep = saturate((base - P.y) / (r * 1.4));
        n = normalize(float3(0.0, -0.3 - 0.6 * deep, 0.7));
        edge = 0.0;
    }
    cover = max(cover, body);
    float low = smoothstep(base - r * 0.4, base + r * 0.9, P.y);
    float4 s = shadeCloud(n, edge, low, P, fog);
    return float4(s.rgb, cover);
}

// A cumulus tower in its cell: puffs stacked from the sea of clouds up to its top. Some cells always have one; more
// grow up out of the sea as the weather clouds over, and sink back as it clears.
float4 tower(float2 P, float drift, float top)
{
    float cell = 540.0;
    float x = P.x + drift;
    float ci = floor(x / cell);
    float4 best = float4(0, 0, 0, 0);
    for (int k = -1; k <= 0; k++)
    {
        float c = ci + k;
        float kind = hash11(c * 3.17 + 0.5);
        float grow = kind > 0.45 ? 1.0 : (kind > 0.12 ? OVERCAST : 0.0);
        if (grow < 0.02) continue;
        float h = hash11(c * 5.93 + 1.7);
        float wide = (58.0 + 46.0 * hash11(c * 9.1 + 4.0)) * lerp(0.6, 1.0, grow);
        float cx = (c + 0.25 + 0.5 * h) * cell - drift;
        float base = BAR * 0.4;
        float height = lerp(0.55, 1.0, hash11(c * 2.3 + 8.0)) * (top - base) * grow;
        // A cauliflower: big puffs low and wide, smaller ones climbing towards a lopsided crown, melted together.
        puffsBegin();
        for (int i = 0; i < 13; i++)
        {
            float t = i / 12.0;
            float hs = hash11(c * 17.0 + i * 3.7), hv = hash11(c * 29.0 + i * 1.3);
            float rr = lerp(0.36, 0.15, t) * wide * (0.75 + 0.5 * hs);
            float spread = wide * 0.55 * (1.0 - 0.75 * t);
            float2 cen = float2(cx + (hv - 0.5) * 2.0 * spread + (t - 0.5) * wide * 0.18, base + t * (height - rr) + rr * 0.35);
            // Higher puffs sit a little in front of the ones below: a crown, not a pile.
            addPuff(P, cen, rr, t * 1.5, 1.08, 0.26);
        }
        float cover = PCOVER;
        if (cover > best.a)
        {
            float edge;
            float3 n = puffNormal(edge);
            float low = smoothstep(base, base + max(height, 1.0) * 0.6, P.y);
            float4 s = shadeCloud(n, edge, low, P, 0.1);
            best = float4(s.rgb, cover);
        }
    }
    return best;
}

// The girl's shadow on the clouds below her: her layer read higher up, squashed (the clouds are seen at a slant).
float girlShadow(float2 P)
{
    float s = 0.0;
    // Cast away from the sun (or moon): to the left of her while it is ahead, under her as she passes it.
    float away = 28.0 * clamp((LIGHTX - P.x) / 240.0, -1.0, 1.0);
    for (int i = -2; i <= 2; i++)
    {
        float x = P.x + away + i * 5.0;
        float alt = BAR + 31.0 + (P.y - BAR * 0.42) * 2.2;
        float r = alt / BAR;
        float2 q = float2(x / WIDTH, bottomEdge > 0.5 ? 1.0 - r : r);
        s += layerBack(q).a;
    }
    return s / 5.0;
}

// Slanting rain: thin streaks falling, one lane every few DIPs, each at its own speed.
float rainAt(float2 P)
{
    float2 q = float2(P.x + P.y * 0.28, P.y);
    float lane = floor(q.x / 3.0);
    float h = hash11(lane * 1.7 + 0.3);
    if (h < 0.5) return 0.0;
    float speed = 150.0 + 90.0 * hash11(lane * 3.1);
    float y = frac((q.y + time * speed + h * 500.0) / 70.0);
    float streak = smoothstep(0.0, 0.05, y) * (1.0 - smoothstep(0.08, 0.2, y));
    float across = 1.0 - abs(frac(q.x / 3.0) - 0.5) * 2.0;
    return streak * saturate(across * 1.6 - 0.3);
}

float3 hueColor(float h) { return saturate(abs(frac(h + float3(1.0, 2.0 / 3.0, 1.0 / 3.0)) * 6.0 - 3.0) - 1.0); }

float4 main(float2 uv : TEXCOORD) : COLOR
{
    BAR = size.y;
    WIDTH = size.x;
    float2 P = float2(uv.x * WIDTH, rise(uv) * BAR);   // DIPs: along the bar, up from the screen's edge
    float room = headroom();
    // The girl (the layer behind, premultiplied): painted here over the sky, in front of the sun, the moon and the
    // stars; the clouds and towers drawn after her still hide her.
    float4 girl = layerBack(uv);

    // ------------------------------------------------------------------ the sky's clock
    PHASE = frac((time + DAYSHIFT) / 240.0 + 0.08);
    NIGHT = smoothstep(0.56, 0.66, PHASE) * (1.0 - smoothstep(0.9, 0.99, PHASE));
    float w = frac((time + WXSHIFT) / 420.0 + 0.1);
    OVERCAST = smoothstep(0.3, 0.45, w) * (1.0 - smoothstep(0.82, 0.95, w));
    RAIN = smoothstep(0.48, 0.56, w) * (1.0 - smoothstep(0.74, 0.82, w));
    float day = 1.0 - NIGHT;
    RAINBOW = smoothstep(0.8, 0.85, w) * (1.0 - smoothstep(0.9, 0.97, w)) * day;

    //                   dawn      day       golden    dusk      night
    LIT = weather(dayColor(0xFFE6EA, 0xFFFFFF, 0xFFF0D2, 0xFFCDA6, 0xC9D4F2), 0.92);
    MID = weather(dayColor(0xE8C6D6, 0xDCE6F1, 0xF1D9BE, 0xE9A99A, 0x7D8AB8), 0.9);
    SHADE = weather(dayColor(0x9C93BE, 0xA9BCD3, 0xA8A6C8, 0x8579AE, 0x45517F), 0.88);
    DEEP = weather(dayColor(0x545585, 0x5E6F92, 0x56588A, 0x4B4376, 0x1F2850), 0.88);
    AIR = weather(dayColor(0xFFC7B8, 0xCFE6F5, 0xFFDDB0, 0xFFAA86, 0x2E3A66), 0.85);
    SKY = weather(dayColor(0x8FA4D8, 0x78B4E4, 0x8FA9D6, 0x7F7FBF, 0x0F1736), 0.8);
    SUNC = dayColor(0xFFD2B0, 0xFFF6E0, 0xFFD58A, 0xFF9A5C, 0xDDE6FF);
    float3 sea = weather(dayColor(0x3C4E7E, 0x2D5F86, 0x2C4E74, 0x343B66, 0x10183A), 0.85);
    float e = lerp(0.3, 0.45 + 0.55 * level, playing);

    // The sun crosses by day (rising at the left, setting at the right), the moon by night.
    float ts = saturate(PHASE / 0.6);
    float tm = saturate(frac(PHASE - 0.58) / 0.44);
    float arcS = sin(3.14159 * ts), arcM = sin(3.14159 * tm);
    float isSun = 1.0 - smoothstep(0.58, 0.62, PHASE);
    float bodyT = lerp(tm, ts, isSun);
    float arc = lerp(arcM, arcS, isSun);
    LIGHTX = WIDTH * lerp(0.04, 0.96, bodyT);
    float bodyY = BAR + BAR * (-0.6 + 1.4 * arc);
    float clear = 1.0 - 0.85 * OVERCAST;
    RIMK = lerp(0.35, 1.0, (1.0 - arc)) * lerp(0.45, 1.0, isSun) * clear * (0.7 + 0.5 * e);

    float horizon = BAR * 0.84;
    float3 col;
    float alpha = 1.0;
    float2 ds = float2(P.x - LIGHTX, P.y - bodyY);
    float bodyR = BAR * lerp(0.26, 0.3, isSun);
    float sd = length(ds);
    // Cloud coming over it softens its rim, then hides it; it stays bright while it shows (never a grey ghost of itself
    // over a dark desktop), and its glow is left behind the cloud.
    float veil = smoothstep(0.2, 0.6, OVERCAST);
    float disc = saturate((bodyR - sd) / (1.0 + 3.0 * veil) + 0.5) * (1.0 - veil);
    // The moon: cream, its seas a soft blue-grey (light, never dark), a little cooler on the side away from the light;
    // the sun: warm, whiter in the middle of the day.
    float2 mq = ds / bodyR;
    float seas = 0.6 * smoothstep(0.42, 0.18, length(mq - float2(-0.25, 0.2)))
               + 0.45 * smoothstep(0.3, 0.1, length(mq - float2(0.28, -0.15)))
               + 0.35 * smoothstep(0.22, 0.05, length(mq - float2(-0.12, -0.45)));
    float3 moonC = lerp(float3(1.0, 0.97, 0.88), float3(0.8, 0.84, 0.93), saturate(seas));
    moonC *= lerp(0.86, 1.0, smoothstep(-1.0, 0.6, mq.x + mq.y * 0.4));
    float3 discC = lerp(moonC, lerp(SUNC, float3(1, 1, 1), 0.2 + 0.5 * arc) * 1.2, isSun);
    float glowAmt = lerp(0.45, 1.0, isSun) * clear;
    float bodyGlow = exp(-length(float2(ds.x, ds.y * 1.6)) / (BAR * 1.3)) * (0.75 + 0.5 * e) * glowAmt;
    // A ring of pale moonlight round it, light on any desktop; behind thin cloud it spreads.
    float halo = exp(-max(sd - bodyR, 0.0) / (BAR * lerp(0.3, 0.6, veil))) * 0.45 * (1.0 - isSun) * clear;
    float3 haloC = float3(0.86, 0.9, 1.0);

    // Stars by night: in the strip of sky, and faintly above the taskbar. A beat makes a few of them sparkle.
    float2 sc = floor(P * 0.5);
    float star = step(0.985, hash12(sc)) * (0.5 + 0.5 * sin(time * (1.5 + 3.0 * hash12(sc + 3.0)) + hash12(sc) * 40.0));
    star *= NIGHT * clear * (1.0 + 1.2 * beat * beat * playing);

    // A rainbow when the rain has gone, standing on the clouds.
    float rbX = WIDTH * (0.3 + 0.4 * hash11(floor((time + WXSHIFT) / 420.0 + 0.1) + 5.0));
    float rbD = length(P - float2(rbX, BAR - 150.0)) - 210.0;
    float rbBand = saturate(1.0 - abs(rbD) / 9.0);
    float3 rbC = hueColor(saturate(0.5 + rbD / 18.0) * 0.78);
    float rbA = rbBand * RAINBOW * 0.4 * smoothstep(BAR * 0.6, BAR * 1.1, P.y);

    // Sky at the horizon: the air glowing right at it, the sun's or moon's glow along it. It thins towards the top of the
    // bar to carry on as the haze above it (no edge where the taskbar ends).
    float3 skyAt = lerp(AIR, SKY, saturate((P.y - horizon) / (BAR * 0.5)));
    col = skyAt + SUNC * (0.5 * bodyGlow + 0.3 * glowAmt * exp(-abs(P.y - horizon) / (BAR * 0.1)) * exp(-abs(ds.x) / (BAR * 9.0)));
    col += float3(0.9, 0.93, 1.0) * star;
    col = lerp(col, rbC, rbA);
    // Nearly solid up to the bar's top, so the taskbar's own colour does not show through as a line along it.
    alpha = max(lerp(1.0, 0.95, smoothstep(horizon - BAR * 0.05, BAR, P.y)), 0.7 * bodyGlow);
    over(col, alpha, haloC, halo);
    over(col, alpha, discC, disc);
    over(col, alpha, girl.rgb / max(girl.a, 0.0001), girl.a);

    // Below the horizon, through the gaps: the sea far down, the light's path glittering on it (more on the beat).
    if (P.y < horizon)
    {
        alpha = 1.0;
        float depth = saturate((horizon - P.y) / horizon);
        float3 s = lerp(lerp(sea, AIR, 0.45), sea * 0.8, depth);
        float path = exp(-abs(P.x - LIGHTX) / (BAR * (1.6 + 2.5 * depth))) * glowAmt;
        float2 cell = floor(float2(P.x * 0.35 + time * 0.6, P.y * 0.9));
        float sparkle = step(0.93, hash12(cell + floor(time * 3.0) * 17.0)) * (1.0 - RAIN);
        s += SUNC * path * (0.25 + sparkle * (0.6 + 1.6 * beat * beat * playing)) * lerp(1.0, 0.5, NIGHT);
        col = s;
    }

    // The sea of clouds: a far row fading into the air, a middle row, a near row; each drifts at its own pace.
    float4 far = cloudRow(P, BAR * 0.66, BAR * 0.16, time * 1.6, 1.0, 0.45, 2.2);
    col = lerp(col, far.rgb, far.a);
    float4 mid = cloudRow(P, BAR * 0.4, BAR * 0.3, time * 3.4, 7.0, 0.18, 1.5);
    col = lerp(col, mid.rgb, mid.a);
    float4 nearRow = cloudRow(P, BAR * 0.1, BAR * 0.52, time * 6.5, 13.0, 0.0, 1.15);
    col = lerp(col, nearRow.rgb, nearRow.a);
    float cloudy = max(max(far.a, mid.a), nearRow.a);
    alpha = lerp(alpha, 1.0, cloudy);

    // Towers rising out of it, up past the taskbar (kept short of the headroom's top, or inside the bar when it's hidden).
    float top = BAR + min(58.0, max(room - 12.0, -BAR * 0.2));
    float4 tw = tower(P, time * 2.4, top);

    // The girl's shadow on the clouds of the bar (not on the gaps of sea); fainter by moonlight and under cloud.
    if (P.y < BAR)
    {
        float sh = saturate(girlShadow(P) * 1.8) * 0.7 * cloudy * lerp(1.0, 0.4, NIGHT) * (1.0 - 0.7 * OVERCAST);
        col = lerp(col, lerp(col, DEEP, 0.65), sh);
    }

    // Above the taskbar: the desktop, with the sky's haze dissolving into it, the sun or moon, stars, a rainbow.
    if (P.y > BAR)
    {
        float up = P.y - BAR;
        // The sky carries on from the bar's top as it is there, and thins out as it goes up.
        alpha = max(0.95 * pow(1.0 - saturate(up / 46.0), 2.2), 0.7 * bodyGlow);
        col = lerp(skyAt, SUNC, saturate(bodyGlow * lerp(3.0, 1.4, isSun)));
        over(col, alpha, float3(0.9, 0.93, 1.0), saturate(star) * 0.8 * (1.0 - smoothstep(20.0, 70.0, up)));
        over(col, alpha, rbC, rbA);
        over(col, alpha, haloC, halo);
        over(col, alpha, discC, disc);
        // Nothing of the sky reaches the headroom's top: glows and the rainbow fade out on the way (the towers stand
        // below it, solid).
        alpha *= 1.0 - smoothstep(room * 0.6, room - 1.0, up);
        over(col, alpha, girl.rgb / max(girl.a, 0.0001), girl.a);
    }
    col = lerp(col, tw.rgb, tw.a);
    alpha = max(alpha, tw.a);

    // Rain, over everything, thinning out above the taskbar.
    if (RAIN > 0.01)
    {
        float r = rainAt(P) * RAIN * (P.y > BAR ? 1.0 - smoothstep(0.0, 70.0, P.y - BAR) : 1.0);
        float3 rc = lerp(float3(0.78, 0.84, 0.95), float3(0.55, 0.62, 0.8), NIGHT);
        col = lerp(col, rc, r * 0.45);
        alpha = max(alpha, r * 0.4);
    }

    // Now and then a few gulls cross by day, high over the clouds.
    float2 ev = rareEvent(41.0, 10.0, 3.0);
    if (ev.x > 0.0 && day * (1.0 - RAIN) > 0.3)
    {
        for (int g = 0; g < 4; g++)
        {
            float2 at = float2(WIDTH * (1.04 - ev.y / 10.0 * 1.12) + g * 26.0 + 9.0 * sin(g * 2.1),
                               BAR + 40.0 + 10.0 * frac(g * 0.618) + 2.0 * sin(time * 1.3 + g));
            float2 q = P - at;
            float flap = sin(time * 9.0 + g * 1.9);
            float ax = abs(q.x);
            float wing = ax * (0.42 * flap + 0.25) - ax * ax * 0.035;
            float d = abs(q.y - wing);
            float gull = saturate(1.1 - d) * step(ax, 7.0);
            col = lerp(col, DEEP * 0.75, gull);
            alpha = max(alpha, gull);
        }
    }

    // Finish: gentle ends, warm highlights to white, a little grain against banding.
    col *= 1.0 - 0.07 * pow(abs(uv.x * 2.0 - 1.0), 6.0);
    col = softWhite(col, 0.6);
    col += (hash12(P * 3.1 + frac(time * 7.13) * 91.7) - 0.5) * 0.02;
    return paint(col, alpha);
}