Đêm Hoa Đăng

by MusicBar, progress bar

A night river glitters as a paper boat carries a star lantern to the playhead, leaving lotus lanterns flickering to the music in its wake. The star rides up above the taskbar and tiny lights drift onto the desktop.

Needs MusicBar 2.0 or newer: this skin uses what older versions don't have (drawing above the taskbar, animations that come with it). Older versions don't list it; update the app to get it.

46 downloads Download file, 37.2 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 79fabf38311bb63a2f43671205130fbe2e167c5d7f1cebd64e90776d584e5158

//! name: Đêm Hoa Đăng
//! author: MusicBar
//! kind: progress
//! headroom: 110
//! description: Sông đêm gợn sóng, thuyền giấy chở đèn ông sao trôi theo bài hát, thả lại sau lưng những đóa hoa đăng lung linh theo nhạc

// The river at night, seen a little from above: navy water with soft ripple lines and the sky's stars glinting in it.
// A paper boat carrying a star lantern (đèn ông sao: two bamboo pentagrams tied tip to tip and pushed apart at the
// inner corners so it bulges, red cellophane, a candle inside, paper tassels on the side points) is the play head.
// Behind it float the lotus lanterns (hoa đăng) it has set on the water: they glow and blink with the music, their
// light pooling round them and breaking into ripples below. The star lantern rides above the taskbar in the headroom,
// golden motes drift up, and now and then a carp leaps. While the headroom is hidden (a window there, a preview tile)
// headroom() is 0 and the lantern stands small beside the sail instead.
// Hash and noise follow docs/skin-art/toolbox.hlsl (Hash without Sine, Dave Hoskins, MIT); the drawing is original.

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); }
float2 hash22(float2 p) { float3 q = frac(p.xyx * float3(0.1031, 0.1030, 0.0973)); q += dot(q, q.yzx + 33.33); return frac((q.xx + q.yz) * q.zy); }
float vnoise(float2 p)
{
    float2 i = floor(p), f = frac(p);
    float2 u = f * f * (3.0 - 2.0 * f);
    float a = hash12(i), b = hash12(i + float2(1.0, 0.0)), c = hash12(i + float2(0.0, 1.0)), d = hash12(i + 1.0);
    return lerp(lerp(a, b, u.x), lerp(c, d, u.x), u.y);
}
float fill(float d, float w) { return saturate(0.5 - d / w); }
float beatAge() { return -0.12 * log(max(beat, 1e-4)); }
float sdSegment(float2 p, float2 a, float2 b) { float2 pa = p - a, ba = b - a; float h = saturate(dot(pa, ba) / max(dot(ba, ba), 1e-8)); return length(pa - ba * h); }
float2 rot(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); }

// A tone map that keeps the hue: candle orange stays orange; only the hottest cores go to white.
float3 toneHue(float3 c)
{
    float m = max(max(c.r, c.g), max(c.b, 1e-4));
    float mt = 1.0 - exp(-1.2 * m);
    return lerp(c * (mt / m), float3(mt, mt, mt), saturate((m - 1.6) / 2.4) * 0.8);
}

// Candle light by heat: 0 deep orange, 1 white-yellow.
float3 candle(float k) { return lerp(float3(1.00, 0.42, 0.10), float3(1.00, 0.93, 0.72), saturate(k)); }

// One cupped petal painted over col: from its base b along the angle ang (0 = straight up), length len, widest
// half-width wid. It is rounder (lighter) down its middle and darker at its sides, deep coral at the base and peach at
// the tip; the candle shines through it (glow); a light rim near the tip; and a soft contact shadow just outside its
// edge darkens the petals behind, which is what makes the tiers read as a cup instead of flat cut-outs.
void paintPetal(float2 q, float px, float fl, float2 b, float ang, float len, float wid, float3 cBase, float3 cTip,
                float glow, inout float3 col, inout float a)
{
    float2 dir = float2(sin(ang), cos(ang));
    float2 pq = q - b;
    float tq = dot(pq, dir), sq = dot(pq, float2(-dir.y, dir.x));
    float tt = saturate(tq / len);
    float prof = wid * pow(max(sin(3.14159 * pow(max(tt, 1e-4), 0.68)), 0.0), 0.95);   // full at a third, a pointed tip
    float d = max(abs(sq) - prof, max(-tq, tq - len));
    col *= 1.0 - 0.38 * exp(-max(d, 0.0) / max(0.045, 1.2 * px)) * step(0.0, d) * step(0.0, tq) * step(tq, len * 1.05);
    float cv = fill(d, px);
    float across = saturate(abs(sq) / max(prof, 1e-3));
    float cup = 1.0 - across * across;
    float3 pc = lerp(cBase, cTip, smoothstep(0.05, 1.0, tt));
    // folded paper: a crease down the middle, the half facing up-left lit, the other in shade; a little roundness
    float litSide = sq > 0.0 ? 1.0 : 0.74;
    pc *= litSide * (0.82 + 0.22 * cup);
    pc += cTip * 0.35 * fill(abs(sq) - 0.008, px) * smoothstep(0.08, 0.25, tt) * (1.0 - smoothstep(0.85, 1.0, tt));
    pc += float3(1.00, 0.56, 0.28) * glow * fl * (1.0 - 0.55 * tt) * (0.5 + 0.5 * cup);
    pc += cTip * 0.30 * fill(abs(d + 0.016) - 0.010, px) * smoothstep(0.4, 0.9, tt);
    col = lerp(col, pc, cv);
    a = max(a, cv);
}

// A lotus lantern seen a little from above, in units of its height (waterline at q.y = 0), about 1.5 wide: a sage
// leaf pad on the water, then three tiers of cupped petals (back, middle, front) round a glowing candle. px: one pixel
// in these units; fl: how brightly it burns. Returns rgb and coverage; the light it gives off goes to halo.
float4 lotus(float2 q, float px, float fl, float hue, out float3 halo)
{
    float2 fp = float2(0.0, 0.66);
    float rf = length(q - fp);
    float3 col = float3(0.0, 0.0, 0.0);
    float a = 0.0;
    // the paper: most are pink like the mockup's, some yellow, red or lilac (Hội An's come in every colour)
    float3 pB = float3(0.80, 0.20, 0.27), pT = float3(1.00, 0.58, 0.52);
    if (hue > 0.62) { pB = float3(0.86, 0.48, 0.08); pT = float3(1.00, 0.86, 0.46); }
    if (hue > 0.77) { pB = float3(0.70, 0.06, 0.08); pT = float3(1.00, 0.42, 0.32); }
    if (hue > 0.90) { pB = float3(0.52, 0.24, 0.60); pT = float3(0.92, 0.72, 0.96); }
    // the leaves under it: paper leaves fanned out round the card base, pointed at the rim; the far side catches the
    // light, a lighter rim, candle-warm in the middle
    float2 lq = (q - float2(0.0, 0.10)) / float2(0.80, 0.16);
    float lobes = 0.11 * pow(abs(cos(atan2(lq.y, lq.x) * 6.0)), 4.0);
    float dl = (length(lq) - 1.0 - lobes) * 0.16;
    float cl = fill(dl, px);
    float3 leaf = lerp(float3(0.11, 0.20, 0.17), float3(0.30, 0.44, 0.36), saturate(lq.y * 0.5 + 0.5));
    leaf += float3(0.25, 0.34, 0.27) * fill(abs(dl + 0.022) - 0.012, px) * saturate(lq.y + 0.4);
    leaf += float3(0.55, 0.30, 0.10) * fl * exp(-length(lq) * 1.3) * 0.30;
    col = leaf;
    a = cl;
    // back tier: five upright petals behind the candle, lit through
    float3 bB = pB, bT = pT;
    paintPetal(q, px, fl, float2(0.0, 0.20), 0.00, 0.56, 0.14, bB, bT, 0.55, col, a);
    paintPetal(q, px, fl, float2(0.0, 0.19), -0.46, 0.56, 0.14, bB, bT, 0.50, col, a);
    paintPetal(q, px, fl, float2(0.0, 0.19), 0.46, 0.56, 0.14, bB, bT, 0.50, col, a);
    paintPetal(q, px, fl, float2(0.0, 0.17), -0.92, 0.54, 0.14, bB, bT, 0.40, col, a);
    paintPetal(q, px, fl, float2(0.0, 0.17), 0.92, 0.54, 0.14, bB, bT, 0.40, col, a);
    // the candle: a cream pillar glowing from inside, the flame on top
    float2 cq = q - float2(0.0, 0.40);
    float dc = max(abs(cq.x) - 0.075, abs(cq.y) - 0.15);
    float cc = fill(dc, px);
    float3 can = lerp(float3(1.00, 0.78, 0.46), float3(1.00, 0.95, 0.82), saturate(cq.y / 0.15 * 0.5 + 0.5)) * (0.9 + 0.5 * fl);
    col = lerp(col, can, cc);
    a = max(a, cc);
    float2 fq = (q - fp) / float2(0.060, 0.15);
    float fd = (length(float2(fq.x * (1.0 + 0.9 * saturate(fq.y)), fq.y)) - 1.0) * 0.06;
    float fc = fill(fd, px);
    float fk = saturate(1.0 - length(fq * float2(1.0, 0.8)));
    col = lerp(col, candle(0.55 + 0.45 * fk) * (1.1 + 0.5 * fl), fc);
    a = max(a, fc);
    // middle tier: four petals opening out
    float3 mB = saturate(pB * 1.06 + 0.02), mT = saturate(pT * 1.04);
    paintPetal(q, px, fl, float2(-0.04, 0.13), -0.70, 0.48, 0.15, mB, mT, 0.32, col, a);
    paintPetal(q, px, fl, float2(0.04, 0.13), 0.70, 0.48, 0.15, mB, mT, 0.32, col, a);
    paintPetal(q, px, fl, float2(-0.06, 0.11), -1.28, 0.50, 0.14, mB, mT, 0.24, col, a);
    paintPetal(q, px, fl, float2(0.06, 0.11), 1.28, 0.50, 0.14, mB, mT, 0.24, col, a);
    // front tier: the nearest, widest petals, low over the leaf; the middle one hides the candle's foot
    float3 fB = saturate(pB * 1.12 + 0.04), fT = saturate(pT * 1.08 + 0.02);
    paintPetal(q, px, fl, float2(-0.08, 0.08), -1.50, 0.46, 0.13, fB, fT, 0.15, col, a);
    paintPetal(q, px, fl, float2(0.08, 0.08), 1.50, 0.46, 0.13, fB, fT, 0.15, col, a);
    paintPetal(q, px, fl, float2(-0.03, 0.07), -0.32, 0.34, 0.15, fB, fT, 0.20, col, a);
    paintPetal(q, px, fl, float2(0.03, 0.07), 0.32, 0.34, 0.15, fB, fT, 0.20, col, a);
    // the light it gives off: a tight glow round the flame (kept off the petals so they keep their colour) and a wide one
    halo = candle(0.6) * fl * (exp(-rf / 0.12) * 0.8 * (1.0 - 0.7 * a * step(q.y, 0.52)) + exp(-rf / 0.65) * 0.16);
    return float4(col, a);
}

// One row of lotus lanterns on the water. cell: their spacing (px); vLo..vHi: where their waterlines sit (shares of
// the bar); sz: their height (px). Behind the boat most cells hold one (it set them afloat), ahead only a few far
// ones. What they light on the water goes to wl, their light in the air to emit; returns the one drawn here.
float4 lanternRow(float x, float y, float H, float hx, float cell, float vLo, float vHi, float sz, float seed,
                  float t, float glowK, float kickB, float rip, inout float3 wl, inout float3 emit)
{
    float j0 = floor(x / cell);
    float4 obj = float4(0.0, 0.0, 0.0, 0.0);
    for (int k = -1; k <= 1; k++)
    {
        float j = j0 + k;
        float r1 = hash11(j * 1.7 + seed), r2 = hash11(j * 3.1 + seed * 2.0), r3 = hash11(j * 5.3 + seed * 3.0);
        float cx = (j + 0.2 + 0.6 * r1) * cell;
        float behind = hx - cx;
        float released = step(0.7 * sz, behind);
        float present = released > 0.5 ? step(r2, 0.82) : step(r2, 0.14);
        // a lantern just let go opens up out of the water
        float grow = released > 0.5 ? smoothstep(0.7 * sz, 2.2 * sz, behind) : 0.75;
        float scl = sz * (0.35 + 0.65 * grow) * (0.85 + 0.3 * r3);
        float bob = sin(t * (1.2 + 0.6 * r3) + r1 * 6.28) * 0.035 * scl;
        float wy = lerp(vLo, vHi, r3) * H + bob;
        float2 q = float2(x - cx, y - wy) / scl;
        q = rot(q, 0.06 * sin(t * (0.9 + 0.5 * r1) + r2 * 6.28));
        // burning: a flicker of its own, the music (half blink on the beat), dimmer ahead of the boat
        float flick = 0.80 + 0.20 * vnoise(float2(t * 7.0, r1 * 37.0));
        float fl = flick * glowK * (1.0 + 0.9 * kickB * step(0.5, r1)) * (released > 0.5 ? 1.0 : 0.65) * present * grow;
        // on the water: a warm pool, the reflection broken by the ripples, a ring spreading out
        float2 wq2 = float2(x - cx, y - wy) / scl;
        float pool = exp(-(wq2.x * wq2.x / 1.8 + wq2.y * wq2.y / 0.05));
        float refl = exp(-wq2.x * wq2.x / 0.07) * exp(min(wq2.y, 0.0) / 1.5) * step(wq2.y, 0.0) * rip;
        float rr = frac(t * 0.30 + r1) * 1.7;
        float rd = (length(float2(wq2.x, wq2.y * 4.0)) - rr) / 0.07;
        float ring = exp(-rd * rd) * (1.0 - rr / 1.7);
        wl += candle(0.35) * fl * (pool * 0.30 + refl * 0.85 + ring * 0.22) + float3(1.0, 0.45, 0.42) * fl * refl * 0.25;
        // the reflection breaks into glitter on the swells
        float cg = max(0.16 * scl, 1.6);
        float2 gq3 = float2(x - cx, y - wy) / cg;
        float2 gi3 = floor(gq3);
        float2 gr3 = hash22(gi3 + j * 3.1 + seed);
        float2 gd3 = (frac(gq3) - 0.2 - 0.6 * gr3) * cg;
        float spk = exp(-dot(gd3, gd3) / 0.35) * step(0.55, gr3.x) * (0.5 + 0.5 * sin(t * (4.0 + 5.0 * gr3.y) + gr3.x * 6.28));
        float reflWide = exp(-wq2.x * wq2.x / 0.22) * exp(min(wq2.y, 0.0) / 1.2) * step(wq2.y, -0.05) + pool * 0.6;
        wl += candle(0.75) * fl * saturate(spk) * reflWide * 1.6;
        if (abs(q.x) < 0.95 && q.y > -0.2 && q.y < 1.0 && present > 0.5)
        {
            float3 halo;
            float4 l = lotus(q, 1.0 / scl, fl, hash11(j * 7.9 + seed * 1.7), halo);
            obj = l;
            emit += halo;
        }
        else
        {
            float rf = length(q - float2(0.0, 0.66));
            emit += candle(0.6) * fl * (exp(-rf / 0.20) * 0.9 + exp(-rf / 0.65) * 0.30);
        }
    }
    return obj;
}

float cross2(float2 a, float2 b) { return a.x * b.y - a.y * b.x; }

// Signed distance to a triangle (< 0 inside).
float sdTri(float2 p, float2 a, float2 b, float2 c)
{
    float d = min(sdSegment(p, a, b), min(sdSegment(p, b, c), sdSegment(p, c, a)));
    float s1 = cross2(b - a, p - a), s2 = cross2(c - b, p - b), s3 = cross2(a - c, p - c);
    bool inside = (s1 >= 0.0 && s2 >= 0.0 && s3 >= 0.0) || (s1 <= 0.0 && s2 <= 0.0 && s3 <= 0.0);
    return inside ? -d : d;
}

// The paper boat as the mockup draws it: an origami boat seen from a little above and in front, low and wide (about
// 2.2 by 1, the keel at q = 0 on the waterline). Its corners, measured off the mockup: the two lifted ends LT, RT; the
// sail's foot SL, SR, its peak PK and the foot of its crease SM; the front wall's lowest top point FC; the keel K and
// the bottom corners BL, BR. Faces: 0 the inside, seen over the front wall (that is the depth), 1 the sail's lit half,
// 2 its shaded half, 3 the front wall's left facet, 4 its right facet. d < 0 inside.
float boatSD(float2 q, out float face)
{
    float2 LT = float2(-1.07, 0.74), SL = float2(-0.34, 0.61), PK = float2(0.01, 1.00), SM = float2(0.02, 0.63);
    float2 SR = float2(0.37, 0.66), RT = float2(1.10, 0.85), FC = float2(0.07, 0.37), K = float2(0.05, 0.00);
    float2 BL = float2(-0.68, 0.12), BR = float2(0.73, 0.10);
    float d0 = min(sdTri(q, LT, SL, FC), min(sdTri(q, SL, SR, FC), sdTri(q, SR, RT, FC)));
    float d1 = sdTri(q, SL, PK, SM);
    float d2 = sdTri(q, SM, PK, SR);
    float d3 = min(sdTri(q, LT, FC, K), sdTri(q, LT, K, BL));
    float d4 = min(sdTri(q, FC, RT, BR), sdTri(q, FC, BR, K));
    // the front wall is nearest, then the sail, then the inside
    face = d3 <= 0.0 ? 3.0 : (d4 <= 0.0 ? 4.0 : (d1 <= 0.0 ? 1.0 : (d2 <= 0.0 ? 2.0 : 0.0)));
    float m = min(min(d0, d1), min(d2, min(d3, d4)));
    if (m > 0.0) face = m == d3 ? 3.0 : (m == d4 ? 4.0 : (m == d1 ? 1.0 : (m == d2 ? 2.0 : 0.0)));
    return m;
}

// The star lantern in units of its outer radius, centre at the origin, a point up. Folded into one point's sector
// (that point along +x): the bulge makes a ridge out to the point (facet sign), the bamboo shows as the outline and
// the inner pentagon. x: the star's distance (< 0 inside), y: the facet side, z: the distance to the bamboo, w: the
// distance from the centre.
float4 starLantern(float2 p, float rin)
{
    float sector = 1.2566371;
    float ang = atan2(p.x, p.y);
    float a = (frac(ang / sector + 0.5) - 0.5) * sector;
    float rho = length(p);
    float2 q = float2(rho * cos(a), rho * abs(sin(a)));
    float2 A = float2(1.0, 0.0);
    float2 B = rin * float2(0.809017, 0.587785);
    float2 e = B - A, w = q - A;
    float h = saturate(dot(w, e) / dot(e, e));
    float d = length(w - e * h);
    float cr = e.x * w.y - e.y * w.x;
    float sd = cr > 0.0 ? -d : d;
    float penta = abs(q.x - rin * 0.809017) + max(q.y - rin * 0.587785, 0.0);   // the inner pentagon's edge
    float bamboo = min(abs(sd), penta);
    return float4(sd, a, bamboo, rho);
}

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float W = size.x, H = size.y;
    float room = headroom();                                  // on screen above the taskbar now (0: hidden)
    bool up = room > 1.0;
    float x = uv.x * W, y = rise(uv) * H;                     // px; y > H in the headroom
    float top = H + room;
    float s = H / 48.0;
    float t = time;
    float on = playing;
    float age = beatAge();
    float lv = lerp(0.35, 0.40 + 0.60 * level, on);
    float kickB = exp(-age * 5.0) * on;
    float v = y / H;

    // ------------------------------------------------------------------ layout (px)
    // the river fills the whole taskbar, edge to edge, square corners
    float xL = 0.0, xR = W, y0 = 0.0, y1 = H;
    float2 bq = abs(float2(x, y) - float2(0.5 * W, 0.5 * H)) - float2(0.5 * W, 0.5 * H);
    float dStrip = length(max(bq, 0.0)) + min(max(bq.x, bq.y), 0.0);
    float inStrip = fill(dStrip, 1.0);
    float hx = lerp(xL + 0.9 * H, xR - 0.9 * H, saturate(progress));
    float Hb = max(0.42 * H, 13.0);                           // the boat's height (it is 2.2 times as wide)
    float ybob = sin(t * 1.4) * 0.016 * H + sin(t * 0.63 + 1.0) * 0.010 * H;
    float yb = 0.25 * H + ybob;                               // its waterline
    float tilt = 0.025 * sin(t * 1.1) + 0.04 * kickB * sin(age * 18.0) * exp(-age * 3.0);
    float glowK = lerp(0.55, 1.0, on) * (0.75 + 0.35 * lv);
    float spX = spectrum(lerp(0.04, 0.80, saturate(x / W)));
    glowK *= 0.85 + 0.40 * spX * on;

    float3 col = float3(0.0, 0.0, 0.0);                       // what is drawn (display colours)
    float cover = 0.0;
    float3 L = float3(0.0, 0.0, 0.0);                         // light (HDR): halos, motes, glows

    // ------------------------------------------------------------------ the river
    float3 wl = float3(0.0, 0.0, 0.0);
    float4 rowF = float4(0.0, 0.0, 0.0, 0.0), rowM = rowF, rowN = rowF;
    float rip = 1.0;
    if (dStrip < 2.0)
    {
        float dep = 1.0 / (1.0 - 0.58 * saturate(v));        // 1 near the screen's edge, 2.4 at the far bank
        float2 wq = float2((x - 0.5 * W) / H * dep * 1.25, dep * 4.6);
        float wn = vnoise(wq + float2(t * 0.18, -t * 0.50)) * 0.62 + vnoise(wq * float2(2.2, 1.8) + float2(-t * 0.30, -t * 0.85) + 5.0) * 0.38;
        // satin swells, as the mockup paints the river: long soft bands lying across it, bending gently as they run,
        // closer together far off; each band's face toward the sky catches a lavender sheen, the troughs sink to deep
        // indigo. The phase is the depth plus a slow sinuous bend; the slope of the swell (its cosine) lights it.
        float depW = 1.0 / (1.0 - 0.42 * saturate(v));                            // the swells foreshorten gently
        float xw = x / H;
        float bend = 0.30 * sin(xw * 0.55 + depW * 1.7 + t * 0.22) + 0.12 * sin(xw * 1.30 - depW * 2.3 - t * 0.31)
                   + 0.22 * (vnoise(float2(xw * 0.35, depW * 1.4) + t * 0.04) - 0.5);
        float ph = depW * 6.5 + bend - t * 0.06;
        float sw = sin(6.2832 * ph);
        float face = cos(6.2832 * ph);                                               // > 0: the face turned to the sky
        float fw = max(fwidth(ph), 1e-4);
        float calm = 1.0 - smoothstep(0.12, 0.32, fw);                               // too fine to draw: let it go flat
        float sheen = pow(saturate(0.5 + 0.5 * face), 2.5) * saturate(0.6 + 0.4 * sw);
        float lip = pow(saturate(face), 4.0) * saturate(sw + 0.3) * 0.5;            // a soft brighter lip on the crest
        float trough = saturate(-face) * saturate(-sw * 0.6 + 0.4);
        float crest = (sheen * 0.70 + lip * 0.35) * calm;
        // the swells break reflections into bands (brightest on the sky-facing faces) and scatter glitter
        rip = 0.18 + 1.15 * saturate(sheen * calm + 0.20 * wn + (1.0 - calm) * 0.4);
        // the colours (measured on the mockup): troughs #15193E, the body #1C2048, faces #2C3268 to #353965, far a
        // touch lighter where it mirrors the sky; very soft brush texture
        float3 deepC = lerp(float3(0.060, 0.072, 0.200), float3(0.085, 0.100, 0.255), smoothstep(0.0, 1.0, v));
        float3 faceC = lerp(float3(0.175, 0.195, 0.420), float3(0.215, 0.230, 0.450), smoothstep(0.0, 1.0, v));
        float3 water = lerp(deepC, faceC, crest);
        water *= 1.0 - 0.42 * trough * calm;
        water += float3(0.20, 0.22, 0.44) * lip * calm * 0.14;
        water *= 0.95 + 0.10 * vnoise(float2(x / (70.0 * s), y / (2.0 * s) + t * 0.05));

        // the stars of the sky glinting in it: more ahead of the boat, where no lanterns are yet
        float2 gc = float2(x / (7.0 * s), y / (3.5 * s));
        float2 gi = floor(gc);
        float2 gr = hash22(gi + 7.0);
        float2 gd = (frac(gc) - 0.2 - 0.6 * gr) * float2(7.0 * s, 3.5 * s);
        float tw = 0.5 + 0.5 * sin(t * (2.0 + 3.0 * gr.x) + gr.y * 6.28);
        float glintOn = step(hash12(gi + 3.3), lerp(0.05, 0.22, smoothstep(-40.0 * s, 40.0 * s, x - hx))) * smoothstep(0.15, 0.6, v) * step(y, y1 - 2.0);
        wl += float3(0.80, 0.86, 1.00) * exp(-dot(gd, gd) / (0.30 * s * s + 0.12)) * glintOn * tw * 1.3;

        // the boat's wake: two lines spreading behind it, and a trail of gold sparkles along the way it came
        float back = hx - x;
        float wakeF = exp(-max(back, 0.0) / (2.6 * H)) * step(0.0, back);
        float wk1 = abs(y - (yb + 0.02 * H + 0.16 * max(back - 0.3 * H, 0.0)));
        float wk2 = abs(y - (yb - 0.02 * H - 0.10 * max(back - 0.3 * H, 0.0)));
        float wake = exp(-min(wk1, wk2) / (0.9 * s + 0.4)) * wakeF * (0.5 + 0.5 * wn);
        wl += float3(0.55, 0.50, 0.70) * wake * 0.35;
        // the way it came: a ribbon of light winding back over the swells, as in the mockup: a soft milky band thick
        // with glitter, brightest by the boat, thinning and fading far behind (but never quite gone: it is the song so far)
        float bendT = saturate(back / (1.4 * H));
        float trailY = yb + 0.05 * H + (0.14 * H * sin(x / (2.1 * H) + 1.3) + 0.05 * H * sin(x / (0.8 * H) + 0.4)) * bendT;
        float tdist = y - trailY;
        float tWide = (0.05 + 0.05 * bendT) * H;
        float tFade = step(0.0, back) * (0.18 + 0.82 * exp(-back / (6.0 * H)));
        float band = exp(-tdist * tdist / (tWide * tWide)) * tFade;
        wl += float3(0.70, 0.72, 0.95) * band * 0.34 * (0.7 + 0.3 * sheen);
        float glit = 0.0;
        for (int g = 0; g < 2; g++)
        {
            float cellG = (2.2 + 1.4 * g) * max(s, 0.75);
            float2 gp = float2(x / cellG, (y - trailY) / cellG + g * 7.3);
            float2 gid = floor(gp);
            float2 gro = hash22(gid + g * 13.0);
            float2 gdl = (frac(gp) - 0.15 - 0.7 * gro) * cellG;
            float twg = 0.5 + 0.5 * sin(t * (2.5 + 5.0 * gro.y) + gro.x * 6.28);
            glit += exp(-dot(gdl, gdl) / (0.22 * s * s + 0.10)) * step(0.70 - 0.10 * g, gro.y) * twg * (1.8 - 0.6 * g);
        }
        wl += float3(1.00, 0.95, 0.82) * glit * exp(-tdist * tdist / (0.7 * tWide * tWide)) * tFade * 1.8;

        // the lanterns, far to near
        float3 eF = float3(0.0, 0.0, 0.0), eM = eF, eN = eF;
        // (sizes in px have a floor, so a 32 px taskbar still shows petals, not dots)
        rowF = lanternRow(x, y, H, hx, max(1.05 * H, 30.0), 0.70, 0.84, max(0.21 * H, 8.0), 11.0, t, glowK * 0.80, kickB, rip, wl, eF);
        rowM = lanternRow(x, y, H, hx, max(1.70 * H, 46.0), 0.47, 0.60, max(0.31 * H, 11.5), 23.0, t, glowK, kickB, rip, wl, eM);
        rowN = lanternRow(x, y, H, hx, max(2.90 * H, 80.0), 0.08, 0.20, max(0.44 * H, 16.0), 37.0, t, glowK, kickB, rip, wl, eN);
        L += eF * 0.8 + eM + eN;

        // the boat and the star lantern on the water: a warm pool, their reflections
        float2 bw = float2(x - hx, y - yb) / Hb;
        float bpool = exp(-(bw.x * bw.x / 2.6 + bw.y * bw.y / 0.05));
        wl += float3(1.00, 0.70, 0.35) * bpool * 0.45 * glowK;
        float faceR;
        float2 mq = float2(bw.x + (rip - 0.6) * 0.06, -bw.y * 1.15 - 0.06);
        float dMir = boatSD(rot(mq, tilt), faceR);
        float mir = fill(dMir * Hb, 1.5) * step(bw.y, 0.0) * exp(bw.y * 2.2);
        wl += float3(0.95, 0.70, 0.32) * mir * rip * 0.55 * glowK;
        float rsx = (x - (hx - 0.50 * Hb)) / (0.10 * H);
        float rstar = exp(-rsx * rsx) * exp(min(bw.y, 0.0) * 1.2) * step(bw.y, -0.05);
        wl += float3(1.00, 0.30, 0.15) * rstar * rip * 0.55 * glowK;

        col = water + toneHue(wl);
        col = lerp(col, rowF.rgb, rowF.a * 0.92);                // far ones sit a little in the haze
        col = lerp(col, rowM.rgb, rowM.a);
        cover = inStrip;
    }

    // ------------------------------------------------------------------ the paper boat
    {
        float2 bq = rot(float2(x - hx, y - yb) / Hb, tilt);
        float face;
        float db = boatSD(bq, face);
        float cb = fill(db * Hb, 1.0) * step(-0.06, bq.y);    // nothing below the waterline
        // warm peach paper, each face its own light: the inside in shade deep down and lighter out at the ends; the
        // sail's left half catching the lantern, its right half turned away; the front wall lighter on the left
        float3 inside = lerp(float3(0.62, 0.26, 0.14), float3(1.00, 0.62, 0.34), saturate(abs(bq.x - 0.05) / 0.95));
        inside *= 0.85 + 0.25 * saturate((bq.y - 0.40) / 0.40);
        float sy = saturate((bq.y - 0.62) / 0.38);
        float3 sailL = lerp(float3(1.00, 0.70, 0.40), float3(1.00, 0.88, 0.64), sy);
        float3 sailR = lerp(float3(0.88, 0.48, 0.26), float3(0.98, 0.68, 0.44), sy);
        float fy = saturate(bq.y / 0.75);
        float3 wallL = lerp(float3(0.82, 0.38, 0.18), float3(1.00, 0.70, 0.42), fy) * (0.92 + 0.12 * saturate(-bq.x));
        float3 wallR = lerp(float3(0.68, 0.30, 0.15), float3(0.94, 0.56, 0.32), fy) * (0.92 + 0.10 * saturate(bq.x));
        float3 bc = face < 0.5 ? inside : (face < 1.5 ? sailL : (face < 2.5 ? sailR : (face < 3.5 ? wallL : wallR)));
        // paper fibres, faint
        bc *= 0.96 + 0.06 * vnoise(bq * float2(38.0, 52.0));
        // the paper's edges catch the light: the front wall's top edge most (it is what shows the depth), the ends'
        // top edges, the sail's crease; the fold down the front a fine line
        float2 LT = float2(-1.07, 0.74), SL = float2(-0.34, 0.61), PK = float2(0.01, 1.00), SM = float2(0.02, 0.63);
        float2 SR = float2(0.37, 0.66), RT = float2(1.10, 0.85), FC = float2(0.07, 0.37), K = float2(0.05, 0.00);
        float ew = 1.0 / Hb;
        float eFront = min(sdSegment(bq, LT, FC), sdSegment(bq, FC, RT));
        float eWing = min(sdSegment(bq, LT, SL), sdSegment(bq, SR, RT));
        bc += float3(1.00, 0.92, 0.76) * fill(eFront - 0.45 * ew, ew) * 0.50;
        bc += float3(1.00, 0.90, 0.74) * fill(eWing - 0.40 * ew, ew) * 0.35;
        bc += float3(1.00, 0.95, 0.85) * fill(sdSegment(bq, PK, SM) - 0.35 * ew, ew) * 0.30;
        bc *= 1.0 - 0.18 * fill(sdSegment(bq, FC, K) - 0.35 * ew, ew);
        // shading under the front edge on the inside: the wall's own shadow
        bc *= 1.0 - 0.30 * exp(-eFront / 0.06) * step(face, 0.5);
        // lit from within: a soft glow in the middle, round the sail's foot, as in the mockup, the ends falling off to
        // orange; a flush on the beat
        float2 gq = (bq - float2(0.05, 0.52)) * float2(0.85, 1.5);
        float inner = exp(-dot(gq, gq) / 0.30);
        bc *= (0.82 + 0.28 * glowK) * lerp(0.78, 1.0, inner);
        bc = lerp(bc, float3(1.00, 0.95, 0.80), inner * 0.80 * glowK);
        bc += float3(0.16, 0.07, 0.02) * glowK + float3(0.25, 0.12, 0.04) * kickB * 0.5;
        // waterline: the paper darkens where it is wet
        bc *= 1.0 - 0.35 * (1.0 - smoothstep(-0.02, 0.07, bq.y));
        col = lerp(col, bc, cb);
        cover = max(cover, cb);
        L += float3(1.00, 0.76, 0.42) * exp(-length(gq) / 0.55) * (1.0 - cb) * 0.30 * glowK;     // its glow round it
    }

    // near lanterns over the boat
    col = lerp(col, rowN.rgb, rowN.a);

    // ------------------------------------------------------------------ the star lantern (đèn ông sao)
    // Made like the classic one: a five-point star whose bamboo frame is taped yellow (the outline and the pentagram's
    // crossings inside), the top and the two lower points green, the side points and the middle red, a white knot drawn
    // in each point and a white ring in the middle; a hoop round it touching the points, wound with pink tinsel; a short
    // pink stick. Where the mockup puts it: up and left of the sail, the stick planted by the sail's foot.
    {
        float Rr = (up ? 0.52 : 0.42) * Hb;                                         // the hoop; the points touch it
        float2 sc = float2(hx - 0.50 * Hb, yb + (up ? 1.38 : 1.26) * Hb);
        float rin = 0.40;
        float sway = 0.05 * sin(t * 1.25 + 0.4) + 0.12 * kickB * sin(age * 16.0) * exp(-age * 2.5);
        float burn = glowK * (0.9 + 0.2 * vnoise(float2(t * 6.0, 3.0)));
        // the stick: short, pink, from inside the boat by the sail up into the star
        float2 poleTop = sc + Rr * rot(float2(0.0, -0.25), sway);
        float2 poleFoot = float2(hx - 0.37 * Hb, yb + 0.54 * Hb);
        float dp = sdSegment(float2(x, y), poleFoot, poleTop);
        float pw = max(0.9, 0.055 * Hb);
        float pc = fill(dp - 0.5 * pw, 0.9) * step(poleFoot.y + 0.03 * Hb, y);
        float3 stickC = float3(0.86, 0.26, 0.54) * (0.55 + 0.45 * burn);
        col = lerp(col, stickC, pc);
        cover = max(cover, pc);
        // the star
        float2 p = rot((float2(x, y) - sc) / Rr, -sway);
        float px = 1.0 / Rr;
        float4 st = starLantern(p * 1.03, rin);                                     // its points just inside the hoop
        float inSt = fill(st.x * Rr, 1.0);
        float rho = st.w;
        float arm = floor(atan2(p.x, p.y) / 1.2566371 + 0.5);                       // 0 the top point, ±1 sides, ±2 lower
        float centre = step(rho * cos(st.y), rin * 0.809017);                      // inside the inner pentagon
        bool green = centre < 0.5 && (abs(arm) < 0.5 || abs(arm) > 1.5);
        float candleK = exp(-rho / 0.45);
        float3 base = green ? float3(0.04, 0.36, 0.14) : float3(0.78, 0.07, 0.07);
        float3 glowC = green ? float3(0.42, 0.96, 0.46) : float3(1.00, 0.48, 0.24);
        float facet = st.y > 0.0 ? 1.0 : 0.78;                                      // the bulge: a ridge out to each point
        float3 cello = lerp(base, glowC, candleK * 0.80 * burn) * facet * (0.70 + 0.40 * burn);
        // white knots in the points, a white ring in the middle (blur to a light patch when small)
        float2 aq = float2(rho * cos(st.y), rho * sin(st.y));
        float lw = max(px, 0.02);
        float knot = max(fill(abs(abs(aq.x - 0.66) + abs(aq.y) * 2.2 - 0.10) - 0.018, lw), fill(length(aq - float2(0.66, 0.0)) - 0.03, lw)) * (1.0 - centre);
        float ringM = fill(abs(rho - 0.21) - 0.016, lw) * centre;
        cello = lerp(cello, float3(1.00, 0.96, 0.86) * (0.75 + 0.3 * burn), saturate(knot + ringM) * 0.85);
        // the yellow tape over the frame
        float tape = fill(st.z * Rr - 0.5 * max(0.9, 0.05 * Rr), 1.0);
        cello = lerp(cello, float3(1.00, 0.86, 0.28) * (0.80 + 0.40 * burn), tape);
        col = lerp(col, cello, inSt);
        cover = max(cover, inSt);
        // the hoop and its pink tinsel: a short strand every few degrees, in or out, glinting
        float rp = length(p);
        float hoop = fill(abs(rp - 1.0) * Rr - 0.5 * max(0.7, 0.03 * Rr), 0.9);
        float nb = 64.0;
        float ab = (atan2(p.x, p.y) / 6.2831853 + 0.5) * nb;
        float bi = floor(ab);
        float2 hr = hash22(float2(bi, 4.0));
        float lenT = (0.10 + 0.16 * hr.y) * (hr.x > 0.42 ? 1.0 : -1.0);
        float across = (frac(ab) - 0.5) * (6.2831853 / nb) * rp;
        float outA = max(max(min(1.0, 1.0 + lenT) - rp, rp - max(1.0, 1.0 + lenT)), 0.0);
        float dT = sqrt(across * across + outA * outA) * Rr;
        float tin = fill(dT - 0.5 * max(0.6, 0.022 * Rr), 0.9) * step(0.18, hash11(bi * 3.7));
        float glint = 0.5 + 0.5 * sin(t * 3.0 + bi * 1.7 + sway * 25.0);
        float3 tinC = lerp(float3(0.62, 0.05, 0.42), float3(1.00, 0.60, 0.88), glint * glint) * (0.55 + 0.55 * burn);
        float tinA = max(hoop, tin);
        col = lerp(col, lerp(float3(0.70, 0.10, 0.48) * (0.6 + 0.4 * burn), tinC, tin), tinA);
        cover = max(cover, tinA);
        // its light round it
        L += float3(1.00, 0.45, 0.22) * exp(-max(st.x, 0.0) * Rr / (0.30 * Rr)) * (1.0 - inSt) * (1.0 - tinA) * 0.35 * burn;
        L += float3(1.00, 0.62, 0.40) * exp(-rp / 1.5) * 0.12 * burn;
    }

    // ------------------------------------------------------------------ in the air: golden motes, a carp now and then
    {
        float topRoom = up ? room : 0.0;
        for (int e = 0; e < 2; e++)
        {
            float fe = e;
            float cell = (11.0 + 6.0 * fe) * s;
            float spd = (9.0 + 6.0 * fe) * s;
            float2 gp = float2(x + 4.0 * s * sin(y / (21.0 * s) + t * (0.6 + 0.3 * fe) + fe * 2.0), y - t * spd) / cell;
            float2 gi = floor(gp);
            float2 gr = hash22(gi + fe * 17.0);
            float2 dd = (frac(gp) - 0.5 - (gr - 0.5) * 0.7) * cell;
            float ex = (gi.x + 0.5) * cell;
            float nearF = 0.06 + 0.94 * exp(-abs(hx - ex) / (3.0 * H));
            float live = step(hash12(gi + 5.0 + fe * 11.0), (0.07 + 0.09 * lv) * nearF * step(ex, hx + 1.5 * H));
            float life = saturate(1.0 - max(y - 0.5 * H, 0.0) / (0.5 * H + topRoom * (0.5 + 0.5 * gr.x)));
            float flick = 0.5 + 0.5 * sin(t * (2.5 + 3.0 * gr.y) + gr.x * 6.28);
            float sz = (0.55 + 0.30 * (1.0 - fe)) * max(s, 0.8);
            float dq = dot(dd, dd);
            L += float3(1.00, 0.82, 0.45) * (exp(-dq / (sz * sz)) * 1.4 + exp(-sqrt(dq) / (2.2 * sz)) * 0.12) * live * life * flick;
        }
        // the carp: every 47 s it leaps out behind the boat in an arc and dives back
        float kp = frac(t / 47.0) * 47.0;
        float kd = 1.7;
        if (kp < kd + 1.2)
        {
            float kid = floor(t / 47.0);
            float kx0 = lerp(xL + 1.5 * H, max(hx - 1.5 * H, xL + 2.0 * H), hash11(kid * 3.7));
            float ph = saturate(kp / kd);
            float span = 2.4 * H;
            float apex = up ? 1.05 * H + 0.35 * room : 0.55 * H;
            float yw = 0.42 * H;
            float2 kpos = float2(kx0 + span * ph, yw + (apex - yw) * 4.0 * ph * (1.0 - ph));
            float2 kvel = normalize(float2(span, (apex - yw) * 4.0 * (1.0 - 2.0 * ph)));
            float Lk = 0.80 * H;
            float2 fq = float2(x, y) - kpos;
            float2 fu = float2(dot(fq, kvel), dot(fq, float2(-kvel.y, kvel.x))) / Lk;   // along the body (head +), across
            float u = fu.x + 0.5;                                                       // 0 tail root .. 1 nose
            float bend = 0.10 * sin(ph * 12.0) * (1.0 - u);
            float wv2 = fu.y - bend;
            // a full body: round at the head, narrowing to the tail's stalk; a dorsal fin along the back
            float eu = (u - 0.60) / 0.60;
            float halfB = 0.19 * sqrt(saturate(1.0 - eu * eu)) * lerp(0.45, 1.0, smoothstep(0.0, 0.55, u));
            float dBody = max(abs(wv2) - halfB, max(-u, u - 1.2)) * Lk;
            float fin = max(max(wv2 - halfB - 0.07 * sin(3.14159 * saturate((u - 0.30) / 0.40)), halfB * 0.6 - wv2), max(0.30 - u, u - 0.70)) * Lk;
            dBody = min(dBody, fin);
            // the tail: a forked fan behind the body
            float tu = -u;
            float tailH = 0.05 + 0.75 * tu;
            float dTail = max(max(abs(wv2) - tailH * 0.32, -tu), tu - 0.30) * Lk;
            float notch = (0.06 * saturate(tu / 0.3) - abs(wv2)) * Lk;                    // the fork in the tail
            dTail = tu > 0.22 ? max(dTail, notch) : dTail;
            float inK = fill(min(dBody, dTail), 1.0) * step(kp, kd);
            float under = step(y, yw - 0.02 * H) * step(0.05, ph) * step(ph, 0.95);              // hidden under the water
            inK *= 1.0 - under;
            // a red carp: red-orange back, gold belly, scales catching the lanterns' light, red fins
            float across = saturate(wv2 / max(halfB, 0.02) * 0.5 + 0.5);                         // 0 belly .. 1 back
            float3 kc = lerp(float3(1.00, 0.70, 0.30), float3(0.92, 0.24, 0.08), smoothstep(0.30, 0.75, across));
            float2 sc2 = float2(u * 14.0, wv2 * 26.0 + 0.5 * frac(u * 7.0));
            float scale = 1.0 - smoothstep(0.30, 0.48, length(frac(sc2) - 0.5));
            kc *= 0.90 + 0.14 * scale * step(0.10, u) * step(u, 0.95);
            kc = lerp(kc, float3(0.90, 0.22, 0.08), step(halfB, wv2) * 0.8);                     // the dorsal fin
            kc *= 0.72 + 0.40 * across;                                                          // lit from above
            kc += float3(1.00, 0.85, 0.55) * exp(-abs(across - 0.78) / 0.06) * 0.25;    // a sheen along the back
            kc = lerp(kc, float3(0.95, 0.30, 0.12), step(u, 0.0) * 0.75);                         // the tail
            float eye = fill(length(float2(u - 1.02, wv2 - 0.04)) * Lk - 0.9 * max(s, 0.8), 0.8);
            kc = lerp(kc, float3(0.05, 0.04, 0.04), eye * step(0.0, u));
            col = lerp(col, kc, inK);
            cover = max(cover, inK);
            // splashes where it leaves the water and where it goes back in: rings and a little spray
            for (int sp = 0; sp < 2; sp++)
            {
                float sx = kx0 + span * (sp == 0 ? 0.04 : 0.96);
                float st0 = sp == 0 ? 0.0 : kd * 0.96;
                float sa = kp - st0;
                float ringR = sa * 0.9 * H;
                float2 sq2 = float2(x - sx, (y - yw) * 3.5);
                float rgd = (length(sq2) - ringR) / (0.6 * s + 0.5);
                float ring = exp(-rgd * rgd) * exp(-sa * 2.0) * step(0.0, sa);
                L += float3(0.85, 0.90, 1.00) * ring * 0.6 * inStrip;
                float spray = exp(-length(float2(x - sx, (y - yw - sa * 0.5 * H * (1.0 - sa))) ) / (1.5 * s)) * exp(-sa * 4.0) * step(0.0, sa);
                L += float3(0.90, 0.95, 1.00) * spray * 0.5;
            }
        }
    }

    // ------------------------------------------------------------------ put together
    // the strip's glass edge and the ends a little dimmer; outside it only light, solid bits and a soft shadow
    col *= lerp(0.88, 1.0, smoothstep(0.0, 0.06, uv.x) * (1.0 - smoothstep(0.94, 1.0, uv.x)));
    float3 lightD = toneHue(L);
    float3 rgb = col + lightD;
    float alpha = max(cover, max(lightD.r, max(lightD.g, lightD.b)));
    rgb += (hash12(uv * size + frac(t * 7.13) * 91.7) - 0.5) * 0.010;
    float a = saturate(max(alpha, max(rgb.r, max(rgb.g, rgb.b))));
    return paint(saturate(rgb) / max(a, 1e-3), a);
}