Ferrofluid
by MusicBar, visualizer
A pool of glossy black ferrofluid along the edge pulls itself into sharp chrome spikes with the bass, and every beat snaps them up taller before they wobble and settle.
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 6b10b626071c0b3b282e1ee6e0bdc32d1d60650724c455e2e5078c73ef6cafa4
//! name: Ferrofluid
//! author: MusicBar
//! kind: visualizer
//! description: A pool of glossy black ferrofluid along the edge pulls itself into sharp chrome spikes with the bass, and every beat snaps them up taller before they wobble and settle.
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);
}
// The studio the fluid mirrors: a dark floor, a soft overhead light, palette panels on both sides, a glow behind.
float3 env(float3 r)
{
float3 c = float3(0.01, 0.01, 0.014) + colorA.rgb * 0.1 * smoothstep(0.0, 0.6, r.y);
c += float3(1.0, 1.0, 1.0) * 1.5 * smoothstep(0.955, 0.995, dot(r, float3(0.0, 0.75, 0.66)));
c += colorB.rgb * 1.5 * smoothstep(0.5, 0.85, r.x) * smoothstep(-0.4, 0.1, r.y);
c += colorC.rgb * 1.5 * smoothstep(-0.5, -0.85, r.x) * smoothstep(-0.4, 0.1, r.y);
c += colorA.rgb * 1.1 * smoothstep(-0.3, -0.85, r.z);
return c;
}
// One row of spikes standing in the pool. Returns the signed distance in pixels (negative inside) and the
// surface normal: each spike is a cone with hollow sides and a needle tip, melted into the pool and its neighbours.
float spikeRow(float2 p, float u, float W, float off, float base, float gain, float bass, out float3 nrm, out float pool)
{
float d = p.y - base;
float3 nSp = float3(0, 0, 0);
pool = 1.0;
float k = 0.16 * u;
float cell = floor((p.x - off) / W);
[unroll] for (int i = -1; i <= 1; i++)
{
float j = cell + i;
float h = hash1(j * 1.37 + off);
float cx = off + (j + 0.5 + 0.2 * (h - 0.5)) * W;
float e = smoothstep(0.12, 0.75, spectrum(saturate(abs(cx / size.x - 0.5) * 2.0) * 0.9));
// Height: the bass pulls the whole field up, the spectrum shapes it, a slow breathing keeps it alive,
// and the beat snaps every spike up taller, ringing as it settles.
float S = u * gain * (0.12 + 0.6 * e + 0.05 * sin(time * 1.7 + j * 2.3)) * (0.75 + 0.45 * bass);
S *= 1.0 + 0.5 * beat + 0.1 * beat * sin(time * 42.0 + j * 1.9);
S = min(S, u * 0.8);
float R = W * (0.5 + 0.15 * e);
float yr = saturate((p.y - base) / S);
float r = R * (1.0 - sqrt(yr));
float lean = R * (0.12 * sin(time * 2.1 + j * 1.7) + 0.3 * beat * sin(time * 37.0 + h * 9.0)) * yr * yr;
float dx = p.x - cx - lean;
float ds = max(max(abs(dx) - r, p.y - base - S), base - p.y);
// Cone normal: around the spike from its axis, tilted up by how fast the side narrows.
float rho = clamp(dx / max(r, 0.5), -1.0, 1.0);
float up = min(R / (2.0 * S * sqrt(max(yr, 0.02))), 1.5);
float3 nS = normalize(float3(rho, up * sqrt(1.0 - rho * rho) + 0.15, sqrt(1.0 - rho * rho)));
// Smooth union, so the spikes rise out of the liquid with a meniscus instead of a corner.
float w = saturate(0.5 + 0.5 * (d - ds) / k);
d = lerp(d, ds, w) - k * w * (1.0 - w);
w *= smoothstep(base - 0.03 * u, base + 0.03 * u, p.y);
nSp = lerp(nSp, nS, w);
pool *= 1.0 - w;
}
// The pool faces us and stays dark; a slow swell runs through it.
float3 nPool = normalize(float3(0.12 * sin(p.x / u * 2.3 + time * 1.4), 0.25, 1.0));
nrm = normalize(nSp + nPool * pool);
return d;
}
// Glossy black: almost no color of its own, a strong mirror at grazing angles, and a sharp highlight.
float3 gloss(float3 n)
{
float3 r = 2.0 * n.z * n - float3(0.0, 0.0, 1.0);
float fres = 0.12 + 0.88 * pow(1.0 - saturate(n.z), 2.5);
float spec = pow(saturate(dot(r, normalize(float3(-0.3, 0.85, 0.45)))), 60.0) * 2.0;
return float3(0.008, 0.008, 0.012) + env(r) * fres + spec;
}
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
// The pool heaps up a little where the music is loud, as if the magnet under it pulled harder.
float heap = smoothstep(0.1, 0.8, spectrum(saturate(abs(uv.x - 0.5) * 2.0) * 0.9));
float bass = spectrum(0.03);
float base = u * (0.11 + 0.03 * level + 0.06 * heap);
float3 acc = float3(0, 0, 0);
float cover = 0;
// The back row: smaller spikes a little higher up, darker and hazed, between the front ones.
float3 nB;
float pB;
float dB = spikeRow(px, u, u * 0.42, u * 0.21, base + 0.05 * u, 0.75, bass, nB, pB);
// The front row.
float3 nF;
float pF;
float dF = spikeRow(px, u, u * 0.48, 0.0, base, 1.0, bass, nF, pF);
// A soft palette glow behind the fluid, so its outline reads on a dark taskbar; it flares on the beat.
float dAll = min(dB, dF);
layer(acc, cover, colorA.rgb, exp(-max(dAll, 0.0) / (0.09 * u)) * step(0.0, dAll) * (0.16 + 0.16 * level + 0.3 * beat));
layer(acc, cover, gloss(nB) * 0.45 + colorA.rgb * 0.04, smoothstep(0.7, -0.7, dB));
layer(acc, cover, gloss(nF), smoothstep(0.7, -0.7, dF));
// The pool's lip catches the light behind it in one thin line.
float lip = smoothstep(0.7, -0.7, dF) * exp(dF / max(0.8, 0.015 * u)) * pF;
layer(acc, cover, lerp(colorA.rgb, float3(1, 1, 1), 0.45), lip * 0.8);
return paint(acc / max(cover, 0.001), cover);
}