Film Reel

by MusicBar, progress bar

A 35 mm film strip runs through a projector gate at the playhead: the frames behind are exposed in warm flickering sepia with scratches, dust and light leaks, the film ahead is still blank, and the strip judders on every beat.

3 downloads Download file, 7.4 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 4c440bec60862c04e0f0003f563edbca0f1ec0bc24aaff1d2e8a561b603835b8

//! name: Film Reel
//! author: MusicBar
//! kind: progress
//! description: A 35 mm film strip runs through a projector gate at the playhead: the frames behind are exposed in warm flickering sepia with scratches, dust and light leaks, the film ahead is still blank, and the strip judders on every beat.

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

// Smooth value noise, for the light leaks.
float vnoise(float2 p)
{
    float2 i = floor(p), f = frac(p);
    f = f * f * (3.0 - 2.0 * f);
    float n = i.x + i.y * 57.0;
    return lerp(lerp(hash1(n), hash1(n + 1.0), f.x), lerp(hash1(n + 57.0), hash1(n + 58.0), f.x), f.y);
}

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); }
float boxD(float2 p, float2 b, float r) { float2 d = abs(p) - b + r; return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - r; }

// 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); }

// What frame i shows, at f (bar heights from the frame's middle): a hazy sunset over hills, the sun
// bouncing a little further from frame to frame like a strip of animation.
float3 picture(float2 f, float i)
{
    float3 sky = lerp(colorA.rgb, colorB.rgb, saturate(f.y / 0.5 + 0.5)) * 0.55 + 0.08;
    float2 sun = float2(-0.12 + 0.08 * sin(i * 0.4), -0.06 + 0.24 * abs(sin(i * 0.55)));
    float ds = length(f - sun);
    float3 img = sky + colorC.rgb * (exp(-ds / 0.07) * 0.35 + smoothstep(0.065, 0.055, ds) * 0.8);
    float hill = f.y + 0.1 - 0.05 * sin(f.x * 9.0 + i * 0.3) - 0.025 * sin(f.x * 21.0 + 1.0);
    img = lerp(img, lerp(colorB.rgb, float3(0.1, 0.06, 0.05), 0.75), smoothstep(0.004, -0.004, hill));
    float g = dot(img, float3(0.3, 0.55, 0.15));
    img = lerp(img, g * float3(1.15, 0.85, 0.55), 0.4);                        // aged toward sepia
    float2 v = f / float2(0.35, 0.25);
    return img * (1.0 - 0.55 * dot(v, v) * dot(v, v));                          // darker corners
}

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float u = size.y;
    float2 px = float2(uv.x * size.x, (1.0 - uv.y) * u);
    float head = progress * size.x;
    float3 acc = float3(0, 0, 0);
    float cover = 0;
    float flick = 0.82 + 0.18 * hash1(floor(time * 24.0)) + 0.1 * level;

    // Film coordinates: the claw pulls the strip left one frame at a time, so a frame always rests in the gate,
    // and the strip judders on the beat.
    float fw = 0.78 * u, pt = time * 1.3;
    float pull = floor(pt) + smoothstep(0.72, 1.0, frac(pt));
    float jud = beat * 0.05 * u * sin(time * 90.0);
    float2 fp = float2(px.x - head + 0.5 * fw + pull * fw + beat * beat * 0.06 * u, px.y - 0.5 * u - jud);
    float exposed = smoothstep(head + 0.04 * u, head - 0.04 * u, px.x);
    float age = lerp(0.65, 1.0, exp(-max(head - px.x, 0.0) / (6.0 * u)));   // film far behind the gate fades back

    // The film base, with sprocket holes punched along both edges (cut right through, so the taskbar shows).
    float sw = 0.26 * u;
    float2 hq = float2((frac(fp.x / sw) - 0.5) * sw, abs(fp.y) - 0.355 * u);
    float dHole = boxD(hq, float2(0.055, 0.038) * u, 0.016 * u);
    float dStrip = abs(fp.y) - 0.44 * u;
    float base = smoothstep(0.5, -0.5, dStrip) * smoothstep(-0.5, 0.5, dHole);
    float3 baseC = lerp(float3(0.07, 0.06, 0.06), float3(0.16, 0.08, 0.035), exposed);
    baseC += float3(0.35, 0.2, 0.08) * smoothstep(1.2, 0.0, abs(dHole)) * exposed;         // light catching the hole edges
    layer(acc, cover, baseC, base * lerp(0.35, 0.92 * age, exposed));

    // Frame lines: blank grey windows ahead, pictures behind.
    float fi = floor(fp.x / fw);
    float2 fq = float2(fp.x - (fi + 0.5) * fw, fp.y);
    float dF = boxD(fq, float2(0.35, 0.25) * u, 0.025 * u);
    layer(acc, cover, float3(0.22, 0.2, 0.2), smoothstep(1.0, 0.0, abs(dF)) * (1.0 - exposed) * 0.5);
    layer(acc, cover, float3(0.1, 0.09, 0.09), smoothstep(0.5, -0.5, dF) * (1.0 - exposed) * 0.25);
    float3 img = picture(fq / u, fi) * flick * (0.85 + 0.15 * hash1(fi * 3.3));

    // Scratches running down the film, flashing for a few frames at a time; dust and hairs on single frames.
    float sc = floor(fp.x / (1.7 * u)), st = floor(time * 9.0);
    float sx = (sc + hash1(sc * 5.1 + st * 0.37)) * 1.7 * u + sin(fp.y / u * 6.0 + sc) * 0.01 * u;
    float scratch = smoothstep(max(0.5, 0.008 * u) + 0.5, 0.0, abs(fp.x - sx)) * step(0.55, hash1(sc * 2.7 + st));
    float2 dc = floor(fp / (0.045 * u));
    float dh = hash1(dc.x * 13.1 + dc.y * 71.7 + floor(time * 24.0) * 3.3);
    float speck = step(0.993 - 0.01 * beat, dh) * smoothstep(0.5, 0.2, length(frac(fp / (0.045 * u)) - 0.5));
    img = lerp(img, float3(1.0, 0.95, 0.85), scratch * 0.55);
    img = lerp(img, frac(dh * 97.0) < 0.5 ? float3(0.02, 0.02, 0.02) : float3(1.0, 0.95, 0.85), speck);
    layer(acc, cover, img, smoothstep(0.5, -0.5, dF) * exposed * age);

    // Light leaks: warm blooms that wander along the exposed film, flaring on the beat.
    float leak = smoothstep(0.45, 0.95, vnoise(float2(fp.x / (2.5 * u) - time * 0.15, 3.0))) * smoothstep(0.1 * u, 0.44 * u, abs(fp.y) + 0.1 * u * sin(fp.x / u));
    layer(acc, cover, lerp(colorA.rgb, float3(1.0, 0.85, 0.5), 0.3), leak * exposed * base * (0.45 + 0.4 * beat));

    // Edge markings between the holes on exposed film.
    float tick = step(abs(fp.y), 0.425 * u) * step(0.405 * u, abs(fp.y)) * step(frac(fp.x / (0.52 * u)), 0.15);
    layer(acc, cover, colorC.rgb * 0.6, tick * exposed * 0.7);

    // The projector gate at the playhead: the frame in it blazes, light blooms around it,
    // and a soft beam with drifting motes throws forward over the blank film.
    float2 gq = px - float2(head, 0.5 * u);
    float dG = boxD(gq, float2(0.36, 0.26) * u, 0.03 * u);
    float lamp = 0.75 + 0.25 * level + 0.35 * beat;
    float3 beamC = lerp(colorC.rgb, float3(1.0, 0.97, 0.9), 0.5);
    float cone = smoothstep(0.26 * u + gq.x * 0.12, 0.0, abs(gq.y)) * smoothstep(-0.1 * u, 0.4 * u, gq.x) * exp(-max(gq.x, 0.0) / (3.0 * u));
    float2 mp = px / (0.12 * u) + float2(-time * 0.6, time * 0.25);
    float mote = smoothstep(0.2, 0.05, length(frac(mp) - 0.5 - 0.3 * (float2(hash1(floor(mp.x) * 3.0 + floor(mp.y) * 17.0), hash1(floor(mp.x) * 7.0 + floor(mp.y) * 5.0)) - 0.5))) * step(0.88, hash1(floor(mp.x) * 11.0 + floor(mp.y) * 23.0));
    layer(acc, cover, beamC, cone * (0.16 + 0.6 * mote * (0.5 + 0.5 * sin(time * 3.0 + mp.x))) * lamp);
    layer(acc, cover, beamC, exp(-max(dG, 0.0) / (0.18 * u)) * 0.45 * lamp);
    layer(acc, cover, img * 1.7 + 0.1, smoothstep(0.5, -0.5, dG) * smoothstep(0.5, -0.5, dF) * 0.85);
    layer(acc, cover, float3(0.15, 0.14, 0.15), smoothstep(1.5, 0.5, abs(dG + 0.5)) * 0.9);

    // Reels at both ends of the bar, spinning as the film runs.
    float2 rq = px - float2(px.x < size.x * 0.5 ? 0.55 * u : size.x - 0.55 * u, 0.5 * u);
    float rr = length(rq);
    float spokes = cos(atan2(rq.y, rq.x) * 3.0 + time * 2.5);
    float dReel = max(rr - 0.47 * u, -max(abs(rr - 0.27 * u) - 0.11 * u, -spokes + 0.35));
    dReel = max(dReel, 0.05 * u - rr);
    layer(acc, cover, float3(0.25, 0.25, 0.28) + colorB.rgb * 0.15 + 0.25 * smoothstep(0.0, 0.47 * u, rq.y + rq.x * 0.3), smoothstep(0.5, -0.5, dReel) * 0.95);
    layer(acc, cover, float3(0.6, 0.6, 0.65), smoothstep(1.2, 0.0, abs(rr - 0.465 * u)) * 0.6);

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