Polygon face
glint · Examples · Tutorials · Gallery
A giant low-poly face in glowing magenta wireframe, singing: its mouth opens with the kicks and the bass, its eyes look about, the head turns a little. Over a hazy stage, with flags waving in the crowd below.
Audio-reactive: it moves with music from a microphone, line-in or a file.

An example in glint, a free live shader editor in the browser: the GLSL code floats over the running picture and recompiles as you type.
The code
One pass, in GLSL.
fragment shader
#version 300 es
precision highp float;
uniform float time;
uniform vec2 resolution;
uniform vec3 spectrum;
uniform float beat;
uniform float beatTime;
uniform int beatCount;
uniform sampler2D fft;
uniform float bpm;
uniform float beatPhase;
uniform float barPhase;
in vec2 v_texcoord;
out vec4 fragColor;
#define PI 3.14159265
// 1 on each kick, fading; without audio, a steady pulse twice a second.
float kick() { return beatCount > 0 ? beat : pow(1.0 - fract(time * 2.0), 4.0); }
float sinceKick() { return beatCount > 0 ? beatTime : fract(time * 2.0) / 2.0; }
float kickId() { return beatCount > 0 ? float(beatCount) : floor(time * 2.0); }
float bin(float x) { return texture(fft, vec2(clamp(x, 0.0, 1.0), 0.25)).r; }
// With no sound in, gentle stand-ins so a visual is never empty: a moving spectrum, a bass that follows the pulse.
float silent() { return step(spectrum.x + spectrum.y + spectrum.z, 0.02); }
float level(float x) { return mix(bin(x), 0.3 + 0.25 * sin(time * 2.3 + x * 17.0) * sin(time * 1.1 + x * 5.0) + 0.15 * kick(), silent()); }
float bass() { return mix(spectrum.x, 0.15 + 0.25 * kick(), silent()); }
float hash(float n) { return fract(sin(n * 127.1) * 43758.5453); }
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
vec2 hash2(vec2 p) { return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453); }
mat2 rot(float a) { float c = cos(a), s = sin(a); return mat2(c, s, -s, c); }
vec3 pal(float t) { return 0.5 + 0.5 * cos(6.28318 * (t + vec3(0.0, 0.33, 0.67))); }
float noise(vec2 p) {
vec2 i = floor(p), f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), f.x), mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), f.x), f.y);
}
float fbm(vec2 p) {
float v = 0.0, a = 0.5;
for (int i = 0; i < 5; i++) { v += a * noise(p); p = rot(0.5) * p * 2.02; a *= 0.5; }
return v;
}
float sdSeg(vec2 p, vec2 a, vec2 b) { vec2 pa = p - a, ba = b - a; float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0); return length(pa - ba * h); }
vec2 vtx(vec2 c, float seed) { return c + 0.42 * (hash2(c + seed) - 0.5); }
// Distance to the nearest mesh edge, in lattice units.
float mesh(vec2 q, float seed) {
vec2 i = floor(q);
float d = 1e9;
for (int y = -1; y <= 1; y++)
for (int x = -1; x <= 1; x++) {
vec2 c = i + vec2(float(x), float(y));
vec2 a = vtx(c, seed), b = vtx(c + vec2(1.0, 0.0), seed), e = vtx(c + vec2(0.0, 1.0), seed), f = vtx(c + vec2(1.0, 1.0), seed);
d = min(d, sdSeg(q, a, b));
d = min(d, sdSeg(q, a, e));
d = min(d, hash(c + seed * 3.0) > 0.5 ? sdSeg(q, a, f) : sdSeg(q, b, e));
}
return d;
}
vec3 neon(float d, vec3 c, float w) { return c * (smoothstep(w, 0.0, d) * 1.2 + exp(-d * 160.0) * 0.35); }
// Stage haze in magenta, truss lights above, light bars and a crowd below.
vec3 stage(vec2 uv, float haze) {
vec3 col = vec3(0.16, 0.0, 0.14) * haze + vec3(0.5, 0.05, 0.45) * exp(-abs(uv.y + 0.25) * 3.0) * 0.35 * haze;
for (int i = 0; i < 12; i++) {
vec2 lp = uv - vec2(-0.85 + float(i) * 0.155, 0.47);
col += vec3(1.0, 0.5, 0.95) * exp(-dot(lp, lp) * 5000.0) * (0.5 + 0.8 * step(0.6, hash(float(i) + kickId())));
}
return col;
}
float crowd(vec2 uv) {
float x = uv.x * 16.0, id = floor(x);
float head = -0.43 + 0.05 * hash(id) + 0.012 * sin(time * 2.0 + id) * kick();
float cx = fract(x) - 0.5;
return max(step(uv.y, -0.47 + 0.02 * hash(id + 3.0)), step(length(vec2(cx / 16.0, uv.y - head) * vec2(16.0, 14.0)), 0.42));
}
float ell(vec2 p, vec2 r) { return (length(p / r) - 1.0) * min(r.x, r.y); }
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * resolution) / resolution.y;
float haze = 0.45 + 0.55 * fbm(uv * 2.5 + vec2(time * 0.04, time * 0.02));
vec3 col = stage(uv, haze);
vec3 pink = vec3(1.0, 0.42, 0.95);
// The head turns a little; features move further than the outline (a hint of depth).
float turn = 0.04 * sin(time * 0.4);
vec2 h = uv - vec2(turn * 0.6, 0.06);
vec2 f = uv - vec2(turn * 1.2, 0.06);
float open = clamp(0.2 + 0.8 * max(kick(), level(0.15) * 1.3), 0.0, 1.0);
// The outline: cranium, jaw, ears, neck, shoulders.
float d = ell(h - vec2(0.0, 0.12), vec2(0.23, 0.3));
d = min(d, ell(h - vec2(0.0, -0.06), vec2(0.185, 0.215)));
d = min(d, ell(vec2(abs(h.x), h.y) - vec2(0.235, 0.02), vec2(0.035, 0.075)));
d = min(d, max(abs(h.x) - 0.11, abs(h.y + 0.34) - 0.1));
float sh = max(abs(h.x) - (0.11 + max(0.0, -0.38 - h.y) * 2.6), h.y + 0.38);
d = min(d, sh);
float mouthD = ell(f - vec2(0.0, -0.135), vec2(0.07, 0.012 + 0.06 * open));
vec3 lines = vec3(0.0);
if (d < 0.0 && mouthD > 0.0) lines += neon(mesh((h + vec2(0.0, 0.3)) * 19.0, 1.0) / 19.0, pink, 0.0018);
lines += neon(abs(d), pink, 0.0022);
// Features.
vec2 fe = vec2(abs(f.x), f.y);
lines += neon(abs(ell(fe - vec2(0.1, 0.035), vec2(0.055, 0.02))), pink, 0.002);
lines += neon(abs(length(fe - vec2(0.1, 0.035) - 0.008 * vec2(sin(time * 0.7), 0.0)) - 0.012), pink, 0.002);
lines += neon(sdSeg(fe, vec2(0.04, 0.085), vec2(0.165, 0.1)), pink, 0.0022);
lines += neon(min(sdSeg(fe, vec2(0.022, 0.02), vec2(0.035, -0.065)), sdSeg(fe, vec2(0.035, -0.065), vec2(0.0, -0.08))), pink, 0.002);
lines += neon(sdSeg(fe, vec2(0.17, 0.0), vec2(0.085, -0.1)), pink, 0.0018);
lines += neon(abs(mouthD), pink, 0.0026);
col = mix(col, vec3(0.02, 0.0, 0.02), step(mouthD, 0.0) * 0.9);
col += lines * (0.9 + 0.7 * kick());
// Flags waving in the crowd, then the crowd itself.
for (int i = 0; i < 4; i++) {
float fi = float(i);
float px = -0.75 + fi * 0.5 + 0.08 * hash(fi);
float top = -0.05 - 0.08 * hash(fi + 5.0);
float pole = step(abs(uv.x - px), 0.002) * step(uv.y, top);
vec2 q = uv - vec2(px, top);
float u = q.x * (mod(fi, 2.0) < 1.0 ? 1.0 : -1.0);
float wave = 0.05 * sin(u * 16.0 - time * 3.5 - fi) * u / 0.2;
float flag = step(0.0, u) * step(u, 0.2) * step(abs(q.y + 0.06 - wave), 0.06);
col = mix(col, vec3(0.06, 0.0, 0.06), max(pole, flag) * 0.95);
}
col = mix(col, vec3(0.0), crowd(uv));
fragColor = vec4(col, 1.0);
}More DJ visuals examples
Ink in water · Deep sea · Laser robots · Neon wireframe head · Polygon dancer · Falling blocks · Pong · Snake