Beat Pads
by MusicBar, visualizer
Rows of rubbery finger-drum pads light up in the palette as the music hits them, each hit rippling its glow out to the pads around it, the kick row flashing on every beat.
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 5d8cc0f87c28c5c78c01acf4177db1d60ee887c21114a236c87241715cbd7207
//! name: Beat Pads
//! author: MusicBar
//! kind: visualizer
//! description: Rows of rubbery finger-drum pads light up in the palette as the music hits them, each hit rippling its glow out to the pads around it, the kick row flashing on every beat.
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);
}
// Signed distance to a rounded box (half size b, corner r).
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; }
float3 swatch(float h) { return h < 0.34 ? colorA.rgb : (h < 0.67 ? colorB.rgb : colorC.rgb); }
// One finger of the player drumming on block b (four columns by three rows), keeping its own rhythm v
// and listening to its own band s: louder means more hits. Light falls on pad (col, rw) of the block: the
// struck pad flares, then a ring of light runs outward over its neighbors. Returns float4(color, light).
float4 hit(float b, float v, float s, float col, float rw)
{
float ph = time * (2.4 + 0.7 * v) + hash1(b * 1.93 + v * 5.1) * 7.0;
float slot = floor(ph);
float local = frac(ph);
float k = b * 3.1 + v * 17.7 + slot * 1.37;
float on = step(hash1(k * 5.3), saturate((s - 0.18) * 1.8));
float2 src = float2(floor(hash1(k * 7.7) * 4.0), floor(hash1(k * 3.1) * 3.0));
float d = length(float2(col, rw) - src);
float ring = exp(-pow((d - local * 4.0) / 0.65, 2.0)) * pow(1.0 - local, 1.5) * 0.8;
float struck = exp(-local * 3.0) * step(d, 0.1);
return float4(swatch(hash1(k * 2.3)), on * max(ring, struck));
}
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 cs = H / 3.0; // one pad cell; three rows fill the bar
float BW = 4.6 * cs; // a block of four columns with a wider gap
float blk = floor(px.x / BW);
float col = clamp(floor((px.x - blk * BW - 0.3 * cs) / cs), 0.0, 3.0);
float rw = clamp(floor(px.y / cs), 0.0, 2.0);
float2 pc = float2(blk * BW + 0.3 * cs + (col + 0.5) * cs, (rw + 0.5) * cs);
float3 acc = float3(0, 0, 0);
float cover = 0;
// The music: each column keeps a faint level meter (bass in the middle of the bar); three fingers
// drum on each block, one on the lows, one on the mids, one on the highs; the beat hits the kick row.
float sx = abs(pc.x / size.x - 0.5) * 2.0;
float bx = abs((blk + 0.5) * BW / size.x - 0.5) * 2.0;
float meter = smoothstep(0.32 + 0.18 * rw - 0.1, 0.32 + 0.18 * rw + 0.08, spectrum(sx * 0.9)) * 0.16;
float4 h0 = hit(blk, 0.0, spectrum(0.03 + 0.2 * bx), col, rw);
float4 h1 = hit(blk, 1.0, spectrum(0.3 + 0.3 * bx), col, rw);
float4 h2 = hit(blk, 2.0, spectrum(0.62 + 0.3 * bx), col, rw);
float kick = beat * step(rw, 0.5) * (0.75 + 0.35 * step(abs(col - 1.5), 1.0));
float lightAmt = saturate(meter + h0.w + h1.w + h2.w + kick);
float3 wt = float3(h0.w, h1.w, h2.w);
wt = wt * wt * wt; // where two hits overlap, the stronger one wins the color
float wm = meter * meter * meter, wk = kick * kick * kick;
float3 col3 = (lerp(colorB.rgb, colorA.rgb, rw * 0.5) * wm + h0.rgb * wt.x + h1.rgb * wt.y + h2.rgb * wt.z + colorC.rgb * wk)
/ max(wm + wt.x + wt.y + wt.z + wk, 0.000001);
// The pad: soft silicone, a little domed, pressed in when struck; lit from inside by its LED.
float press = saturate(h0.w + h1.w + h2.w + kick - 0.5);
float2 pq = px - pc;
float hs = cs * 0.42 * (1.0 - 0.05 * press);
float dP = boxD(pq, float2(hs, hs), cs * 0.13);
float2 n = pq / hs;
float bevel = smoothstep(-0.1 * cs, 0.0, dP);
// Its glow spills into the gaps around it.
layer(acc, cover, col3, exp(-max(dP, 0.0) / (0.05 * cs)) * step(0.0, dP) * lightAmt * 0.7);
float3 rubber = float3(0.17, 0.17, 0.19) * (0.85 + 0.25 * (n.y * 0.5 - n.x * 0.2));
rubber += float3(1, 1, 1) * 0.14 * bevel * saturate(n.y) - 0.06 * bevel * saturate(-n.y);
float sheen = exp(-dot(n - float2(-0.35, 0.45), n - float2(-0.35, 0.45)) * 3.0); // the soft satin of silicone
rubber += float3(1, 1, 1) * 0.06 * sheen;
float core = saturate(1.0 - dot(n, n) * 0.45);
float3 emis = col3 * (0.5 + 0.65 * core) + float3(1, 1, 1) * pow(lightAmt, 2.0) * 0.4 * core * core;
emis *= 1.0 - 0.25 * bevel * saturate(-n.y);
emis += float3(1, 1, 1) * 0.12 * sheen;
float3 padC = lerp(rubber, emis, saturate(lightAmt * 1.3));
layer(acc, cover, padC, smoothstep(0.5, -0.5, dP) * lerp(0.32, 1.0, saturate(lightAmt * 1.6)));
// A thin rim so the grid reads even when it is dark, brighter on the top edge.
float rim = smoothstep(1.2, 0.0, abs(dP + 0.6)) * (0.18 + 0.2 * saturate(n.y));
layer(acc, cover, lerp(float3(0.6, 0.62, 0.68), col3, saturate(lightAmt * 2.0)), rim * (1.0 - 0.5 * lightAmt));
return paint(acc / max(cover, 0.001), cover);
}