DNA Helix

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

Chuỗi xoắn kép DNA xoay 3D dọc phần đã phát, các cặp base sáng lên theo nhạc, chỗ đang phát có hạt enzyme phát sáng đang ráp chuỗi, phía trước chỉ lác đác vài nucleotide trôi lơ lửng.

2 lượt tải Tải file, 7.4 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 7d55457786f36e288a3046e8c87ee69490909536ee1790145affa50ff3e6bd83

//! name: DNA Helix
//! author: MusicBar
//! kind: progress
//! description: A double helix turns in 3D along the played part with its base pairs lighting up to the music, built at the playhead by a glowing enzyme bead, while a few loose nucleotides drift in the dark ahead.

float hash1(float n) { return frac(sin(n * 127.1 + 311.7) * 43758.5453); }

// 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 glossy tube seen side on: v is -1..1 across it, z how near it is (-1 back, 1 front).
float3 tube(float v, float z, float3 base)
{
    float nz = sqrt(saturate(1.0 - v * v));
    float dif = saturate(0.25 + 0.55 * nz + 0.45 * v);
    float spec = pow(saturate(0.8 * nz + 0.55 * v), 30.0);
    return base * (0.3 + 0.85 * dif) * (0.45 + 0.55 * (0.5 + 0.5 * z)) + spec * 0.7;
}

// The four bases: two pair types, each either way round, colored from the palette.
float3 baseColor(float t)
{
    float3 c = t < 0.5 ? lerp(colorC.rgb, float3(1, 1, 1), 0.15) : lerp(colorA.rgb, float3(1, 1, 1), 0.35);
    c = t < 1.5 ? c : (t < 2.5 ? lerp(colorB.rgb, float3(1, 1, 1), 0.35) : lerp(colorC.rgb, colorB.rgb, 0.45));
    return c;
}

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float u = size.y;
    float2 px = float2(uv.x * size.x, rise(uv) * size.y);     // pixels: along the bar, up from the screen edge
    float head = progress * size.x;
    float3 acc = float3(0, 0, 0);
    float cover = 0;

    float y0 = 0.5 * u, A = 0.29 * u, K = 6.2832 / (1.9 * u);
    float spin = time * 1.5 + 0.4 * level;
    float sp = 1.9 * u / 8.0;                                  // eight base pairs a turn
    float behind = head - px.x;
    float built = smoothstep(0.0, 0.25 * u, behind);

    // The two backbones: same helix, the second turned 140 degrees, which opens a wide and a narrow groove.
    float th = px.x * K - spin;
    float y1 = y0 + A * sin(th), z1 = cos(th);
    float y2 = y0 + A * sin(th + 2.45), z2 = cos(th + 2.45);
    float r1 = u * (0.052 + 0.018 * z1), r2 = u * (0.052 + 0.018 * z2);
    float v1 = (px.y - y1) / sqrt(1.0 + pow(A * K * cos(th), 2.0)) / r1;
    float v2 = (px.y - y2) / sqrt(1.0 + pow(A * K * cos(th + 2.45), 2.0)) / r2;
    float a1 = smoothstep(1.0 + 0.6 / r1, 1.0 - 0.6 / r1, abs(v1)) * built;
    float a2 = smoothstep(1.0 + 0.6 / r2, 1.0 - 0.6 / r2, abs(v2)) * built;
    float bead1 = 0.88 + 0.12 * sin(th * 8.0);                      // phosphate bumps along the backbone
    float3 c1 = tube(clamp(v1, -1.0, 1.0), z1, colorA.rgb * bead1);
    float3 c2 = tube(clamp(v2, -1.0, 1.0), z2, colorB.rgb * bead1);

    // A beat sends a pulse of light back down the strands from the bead.
    float pulse = exp(-abs(behind - (1.0 - beat) * 6.0 * u) / (0.7 * u)) * beat;
    c1 = lerp(c1, lerp(colorA.rgb, float3(1, 1, 1), 0.5), pulse * 0.8);
    c2 = lerp(c2, lerp(colorB.rgb, float3(1, 1, 1), 0.5), pulse * 0.8);

    // Back strand first.
    float frontIs1 = step(z2, z1);
    layer(acc, cover, lerp(c1, c2, frontIs1), lerp(a1, a2, frontIs1));

    // Base pairs: rungs across the helix, two halves meeting in the middle, lit by the spectrum.
    float k = floor(px.x / sp);
    float xk = (k + 0.5) * sp;
    float tk = xk * K - spin;
    float ry1 = y0 + A * sin(tk), ry2 = y0 + A * sin(tk + 2.45);
    float f = (px.y - ry1) / (ry2 - ry1);
    float rz = lerp(cos(tk), cos(tk + 2.45), f);
    float rw = u * (0.03 + 0.008 * rz);
    float rung = smoothstep(rw + 0.6, rw - 0.6, abs(px.x - xk)) * step(0.0, f) * step(f, 1.0);
    rung *= smoothstep(0.015, 0.05, abs(f - 0.5));                // the hydrogen bond gap
    float bt = floor(hash1(k * 3.7) * 4.0);
    float3 bc = f < 0.5 ? baseColor(bt) : baseColor(3.0 - bt);
    float s = spectrum(abs(frac(k / 28.0) * 2.0 - 1.0));
    s = smoothstep(0.15, 0.7, s);
    float lit = 0.2 + 1.5 * s * s + 0.8 * pulse;
    float fresh = smoothstep(0.3 * u, 0.9 * u, head - xk);        // the newest pairs snap in at the bead
    float shadeR = 0.55 + 0.45 * (0.5 + 0.5 * rz);
    float gy = max(max(min(ry1, ry2) - px.y, px.y - max(ry1, ry2)), 0.0);
    float gd = length(float2(max(abs(px.x - xk) - rw, 0.0), gy));
    layer(acc, cover, bc, exp(-gd / (0.035 * u)) * smoothstep(0.5 * sp, 0.25 * sp, abs(px.x - xk)) * fresh * saturate(lit - 0.3) * 0.7);
    layer(acc, cover, lerp(bc * shadeR * (0.28 + 0.8 * lit), float3(1, 1, 1), 0.4 * saturate(lit - 1.0)), rung * fresh);

    // Front strand over the rungs.
    layer(acc, cover, lerp(c2, c1, frontIs1), lerp(a2, a1, frontIs1));

    // Ahead: loose nucleotides drifting in the dark, a dot and its base, faint; near the bead they are drawn in.
    float cw = 0.5 * u;
    float ci = floor(px.x / cw);
    float h = hash1(ci * 7.13 + 1.0);
    float2 nc = float2((ci + 0.3 + 0.4 * hash1(ci * 2.9)) * cw, u * (0.2 + 0.6 * h));
    nc += u * float2(0.08 * sin(time * 0.9 + h * 17.0), 0.07 * cos(time * 0.7 + h * 11.0));
    float pull = smoothstep(2.2 * u, 0.4 * u, nc.x - head);
    nc = lerp(nc, float2(nc.x - 0.12 * u, y0 + (nc.y - y0) * 0.4), pull);
    float ang = time * (0.4 + h) * (1.0 + 2.0 * pull) + h * 30.0;
    float2 dq = px - nc;
    float2 dir = float2(cos(ang), sin(ang));
    float stick = length(dq - dir * clamp(dot(dq, dir), 0.0, 0.13 * u)) - 0.022 * u;
    float blob = length(dq) - 0.045 * u;
    float nuc = smoothstep(0.6, -0.6, min(stick, blob)) * step(0.3, hash1(ci * 5.1)) * smoothstep(head + 0.3 * u, head + 0.5 * u, nc.x);
    float3 nucC = lerp(baseColor(floor(h * 4.0)), colorA.rgb, step(blob, stick) * 0.6);
    layer(acc, cover, nucC, nuc * (0.3 + 0.5 * pull));

    // The enzyme at the playhead: a lumpy glass bead with the helix showing through it and a hot core where
    // the new pair is joined; its lobes slowly knead, and it swells and flashes on the beat.
    float2 bq = px - float2(head, y0);
    float br = u * (0.3 + 0.05 * beat + 0.015 * sin(time * 2.7));
    float2 l1 = u * float2(0.2 * cos(time * 1.3), 0.14 * sin(time * 1.7));
    float2 l2 = u * float2(-0.17 * cos(time * 1.1 + 2.0), 0.16 * sin(time * 1.4 + 1.0));
    float e1 = length(bq) - br, e2 = length(bq - l1) - 0.19 * u, e3 = length(bq - l2) - 0.17 * u;
    float hk = saturate(0.5 + 0.5 * (e2 - e1) / (0.08 * u));
    float dB = lerp(e2, e1, hk) - 0.08 * u * hk * (1.0 - hk);
    float crease = hk * (1.0 - hk);
    hk = saturate(0.5 + 0.5 * (e3 - dB) / (0.08 * u));
    dB = lerp(e3, dB, hk) - 0.08 * u * hk * (1.0 - hk);
    crease = max(crease, hk * (1.0 - hk));
    float ba = atan2(bq.y, bq.x);
    dB += 0.005 * u * (sin(ba * 7.0 + time * 1.5) + 0.7 * sin(ba * 12.0 - time * 1.1));   // a slightly knobbly protein skin
    layer(acc, cover, colorC.rgb, exp(-max(dB, 0.0) / (0.16 * u)) * (0.3 + 0.25 * level + 0.45 * beat));
    float rim = saturate(1.0 + dB / (0.13 * u));                  // 1 at the skin, 0 deep inside
    float2 sn = bq / (br + 0.16 * u);
    float3 n = normalize(float3(sn, sqrt(saturate(1.0 - dot(sn, sn))) + 0.05));
    float3 beadC = colorC.rgb * (0.3 + 0.25 * n.z) + lerp(colorC.rgb, float3(1, 1, 1), 0.45) * rim * rim * 0.9;
    beadC *= 1.0 - 0.45 * crease * 4.0 * (1.0 - rim);
    beadC += pow(saturate(dot(n, normalize(float3(-0.5, 0.6, 0.65)))), 36.0) * 0.9;
    beadC += lerp(colorC.rgb, float3(1, 1, 1), 0.6) * exp(-length(bq) / (u * (0.07 + 0.04 * beat))) * (1.2 + beat);
    layer(acc, cover, beadC, smoothstep(0.6, -0.6, dB) * (0.55 + 0.45 * rim));

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