Audio spectrum

glint · Examples · Tutorials · Gallery

Reacts to the microphone or an audio file: turn on audio input in the Inputs panel.

Audio-reactive: it moves with music from a microphone, line-in or a file.

Audio spectrum: an audio-reactive GLSL shader

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 sampler2D fft;

in vec2 v_texcoord;
out vec4 fragColor;

void main() {
    vec2 uv = v_texcoord;
    float bars = 64.0;
    float i = floor(uv.x * bars);
    // Log-ish frequency axis: more room for the bass.
    float f = pow((i + 0.5) / bars, 2.0) * 0.6;
    float level = texture(fft, vec2(f, 0.25)).r;
    float wave = texture(fft, vec2(uv.x, 0.75)).r;

    vec3 col = vec3(0.02, 0.02, 0.05) + spectrum.x * vec3(0.3, 0.05, 0.2);
    float bar = step(uv.y, level) * step(0.15, fract(uv.x * bars));
    col += bar * (0.5 + 0.5 * cos(6.28 * (uv.y * 0.6 + vec3(0.0, 0.33, 0.67) + time * 0.1)));
    col += smoothstep(0.006, 0.0, abs(uv.y - wave)) * vec3(1.0);
    fragColor = vec4(col, 1.0);
}

More Starters examples

Raymarcher · Feedback trails · Vertex art · Lit mesh · Webcam kaleidoscope · Shadertoy style