Oscilloscope trails

glint · Examples · Tutorials · Gallery

The live waveform as a glowing trace, smeared into trails by a zooming, rotating feedback pass.

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

Oscilloscope trails: 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 vec3 spectrumIntegrated;
uniform float beat;
uniform int beatCount;
uniform sampler2D fft;
uniform sampler2D feedback;
uniform float trail;

in vec2 v_texcoord;
out vec4 fragColor;

void main() {
    vec2 uv = v_texcoord;
    // Previous frame, pulled towards the centre and turned a little: trails flow outwards.
    vec2 c = uv - 0.5;
    float a = 0.01 + 0.03 * spectrum.y;
    c = mat2(cos(a), -sin(a), sin(a), cos(a)) * c * (0.97 - 0.03 * beat);
    vec3 prev = texture(feedback, c + 0.5).rgb * trail;
    // The waveform across the screen.
    float w = texture(fft, vec2(uv.x, 0.75)).r - 0.5;
    w += 0.02 * sin(uv.x * 20.0 + time * 4.0);    // idle motion in silence
    float d = abs(uv.y - 0.5 - w * 0.8);
    vec3 hue = 0.5 + 0.5 * cos(6.28318 * (time * 0.05 + uv.x * 0.3 + vec3(0.0, 0.33, 0.67)));
    vec3 col = hue * smoothstep(0.006, 0.0, d) * (1.0 + 2.0 * spectrum.x);
    fragColor = vec4(max(prev, col), 1.0);
}

More Starters examples

Ridgelines · Kaleido pulse · Laser show · Metaballs · Hyperspace · Strobe grid