Laser Show

by MusicBar, visualizer

Laser fans sweep out of projectors along the edge through the haze of a concert, opening into more beams as the music swells, with white-hot cores and strobes flashing on every beat.

7 downloads Download file, 6.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 a23810457a2f11e6778110505744fe21db9e83e2c27439200b8690e007cd485f

//! name: Laser Show
//! author: MusicBar
//! kind: visualizer
//! description: Laser fans sweep out of projectors along the edge through the haze of a concert, opening into more beams as the music swells, with white-hot cores and strobes flashing on every beat.

float hash2(float2 p) { float3 q = frac(float3(p.x, p.y, p.x) * 0.1031); q += dot(q, q.yzx + 33.33); return frac((q.x + q.y) * q.z); }

// Smooth value noise, for the drifting haze.
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);
}

float3 swatch(float j) { float k = j - floor(j / 3.0) * 3.0; return k < 0.5 ? colorA.rgb : (k < 1.5 ? colorB.rgb : colorC.rgb); }

// The fan of projector j standing at e: up to nine beams around a center angle that sweeps to and fro.
// The outer beams switch on as the music swells and the fan tightens.
// Returns x: glow, y: the colored beam, z: the wide scatter the haze throws around it, w: its white-hot core.
float4 fan(float2 px, float2 e, float j, float s, float H)
{
    float2 q = px - e;
    float r = length(q);
    float th = atan2(q.x, q.y);                                    // angle from straight up
    float dirn = (frac(j * 0.5) < 0.25) ? 1.0 : -1.0;
    float c = dirn * 1.0 * sin(time * (0.45 + 0.1 * frac(j * 0.37)) + j * 1.7);
    float drive = saturate(level * 0.9 + 0.35 * beat + 0.2 * s);
    float sp = lerp(0.2, 0.085, drive) * (1.0 + 0.15 * sin(time * 0.8 + j));
    float kf = (th - c) / sp;
    float kmax = min(floor((drive + 0.1) / 0.12), 4.0);                      // the beams that are on at all
    float lo = max(-kmax, ceil((-1.32 - c) / sp)), hi = min(kmax, floor((1.32 - c) / sp));
    float k = clamp(floor(kf + 0.5), lo, hi);
    float k2 = clamp(k + (kf > k ? 1.0 : -1.0), lo, hi);
    float vis1 = smoothstep(0.12 * abs(k) - 0.1, 0.12 * abs(k), drive) * smoothstep(1.32, 1.22, abs(c + k * sp));
    float vis2 = smoothstep(0.12 * abs(k2) - 0.1, 0.12 * abs(k2), drive) * smoothstep(1.32, 1.22, abs(c + k2 * sp)) * step(0.5, abs(k2 - k));
    float d1 = r * abs(sin(th - (c + k * sp)));
    float d2 = r * abs(sin(th - (c + k2 * sp)));
    float wc = max(0.55, 0.011 * H) + r * 0.003;
    float wg = 0.05 * H + r * 0.012;
    float fall = exp(-r / (6.0 * H)) * (0.65 + 0.5 * s);
    float glow = (exp(-d1 / wg) * vis1 + exp(-d2 / wg) * vis2) * fall;
    float core = (smoothstep(wc * 1.3 + 0.6, wc * 1.3 - 0.6, d1) * vis1 + smoothstep(wc * 1.3 + 0.6, wc * 1.3 - 0.6, d2) * vis2) * fall;
    float hot = (smoothstep(wc * 0.5 + 0.5, wc * 0.5 - 0.5, d1) * vis1 + smoothstep(wc * 0.5 + 0.5, wc * 0.5 - 0.5, d2) * vis2) * fall;
    float ws = 0.22 * H + r * 0.05;
    float wide = (exp(-d1 / ws) * vis1 + exp(-d2 / ws) * vis2) * fall * 0.5 + exp(-r / (0.7 * H)) * 0.35;
    return float4(glow, core, wide, hot) * smoothstep(0.0, 0.15 * H, r);
}

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float2 px = float2(uv.x * size.x, rise(uv) * size.y);   // pixels: along the bar, up from the screen edge
    float H = size.y;
    float E = 4.5 * H;                                       // one projector every E
    float j = floor(px.x / E);
    float3 acc = float3(0, 0, 0);
    float cover = 0;

    // Haze: slow smoke drifting through, so the beams light up in patches.
    float2 hp = px / H * float2(0.8, 1.6) + float2(time * 0.25, -time * 0.1);
    float haze = vnoise(hp) * 0.65 + vnoise(hp * 2.3 + 5.0) * 0.35;
    haze = 0.3 + 1.1 * haze * haze;

    // The strobe lights the whole haze for a blink on the beat.
    layer(acc, cover, float3(0.9, 0.92, 1.0), beat * beat * 0.16 * haze);

    // Three nearby projectors, each in its palette color.
    float2 e0 = float2((j - 0.5) * E, 0.0), e1 = float2((j + 0.5) * E, 0.0), e2 = float2((j + 1.5) * E, 0.0);
    float s0 = spectrum(saturate(abs(e0.x / size.x - 0.5) * 1.6));
    float s1 = spectrum(saturate(abs(e1.x / size.x - 0.5) * 1.6));
    float s2 = spectrum(saturate(abs(e2.x / size.x - 0.5) * 1.6));
    float4 f0 = fan(px, e0, j - 1.0, s0, H);
    float4 f1 = fan(px, e1, j, s1, H);
    float4 f2 = fan(px, e2, j + 1.0, s2, H);
    float3 c0 = swatch(j - 1.0), c1 = swatch(j), c2 = swatch(j + 1.0);
    float wide = f0.z + f1.z + f2.z;
    float3 wcol = (c0 * f0.z + c1 * f1.z + c2 * f2.z) / max(wide, 0.0001);
    float glow = f0.x + f1.x + f2.x;
    float3 gcol = (c0 * f0.x + c1 * f1.x + c2 * f2.x) / max(glow, 0.0001);
    float core = f0.y + f1.y + f2.y;
    float3 ccol = (c0 * f0.y + c1 * f1.y + c2 * f2.y) / max(core, 0.0001);

    // Beams: a wide colored scatter where the haze is thick, the beam's own glow, then the white-hot core.
    layer(acc, cover, wcol, wide * haze * haze * 0.3 * (0.7 + 0.5 * level));
    layer(acc, cover, gcol, glow * haze * (0.5 + 0.3 * beat));
    layer(acc, cover, lerp(ccol, float3(1, 1, 1), 0.15 + 0.3 * beat), core * (0.8 + 0.3 * haze));
    layer(acc, cover, lerp(ccol, float3(1, 1, 1), 0.75), (f0.w + f1.w + f2.w) * (0.6 + 0.4 * beat));

    // The projectors at the screen edge: a dark housing and a blazing aperture.
    float2 pq = px - e1;
    float2 bd = abs(pq - float2(0.0, 0.06 * H)) - float2(0.2 * H, 0.06 * H);
    float box = length(max(bd, 0.0)) + min(max(bd.x, bd.y), 0.0) - 0.02 * H;
    layer(acc, cover, float3(0.1, 0.1, 0.12) + 0.25 * smoothstep(0.0, 0.1 * H, pq.y) * step(box, -0.01 * H), smoothstep(0.5, -0.5, box));
    float ap = length(pq - float2(0.0, 0.12 * H));
    layer(acc, cover, c1, exp(-ap / (0.18 * H)) * (0.6 + 0.4 * level));
    layer(acc, cover, lerp(c1, float3(1, 1, 1), 0.7), smoothstep(0.05 * H, 0.01 * H, ap));

    // Strobes between the projectors: white panels that flash on the beat, with a starburst.
    float2 sq = px - float2(floor(px.x / E + 0.5) * E, 0.07 * H);
    float flash = beat * beat;
    layer(acc, cover, lerp(float3(0.3, 0.3, 0.34), float3(1, 1, 1), flash), smoothstep(1.1, 0.9, max(abs(sq.x) / (0.12 * H), abs(sq.y) / (0.05 * H))));
    float star = exp(-length(sq) / (0.35 * H)) + exp(-abs(sq.y) / (0.02 * H) - abs(sq.x) / (1.2 * H)) + exp(-abs(sq.x) / (0.02 * H) - abs(sq.y) / (0.6 * H));
    layer(acc, cover, float3(1, 1, 1), star * flash * 0.9);

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