Hyperspace

glint · Examples · Tutorials · Gallery

Warp-speed starfield: the bass is the throttle, kicks stretch the stars into streaks.

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

Hyperspace: 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;

in vec2 v_texcoord;
out vec4 fragColor;

float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }

void main() {
    vec2 uv = (gl_FragCoord.xy - 0.5 * resolution) / resolution.y;
    float travel = time * 0.2 + spectrumIntegrated.x * 1.5;
    vec3 col = vec3(0.0);
    for (int layer = 0; layer < 5; layer++) {
        float depth = fract(float(layer) / 5.0 - travel);
        float scale = mix(20.0, 0.5, depth);
        float fade = smoothstep(0.0, 0.3, depth) * smoothstep(1.0, 0.8, depth);
        vec2 p = uv * scale + float(layer) * 17.0;
        vec2 id = floor(p), f = fract(p) - 0.5;
        float h = hash(id);
        vec2 star = f - (vec2(hash(id + 1.3), hash(id + 7.1)) - 0.5) * 0.7;
        // Streak along the radial direction, longer on kicks.
        vec2 dir = normalize(uv + 1e-4);
        float along = dot(star, dir), across = dot(star, vec2(-dir.y, dir.x));
        float len = 0.02 + 0.3 * beat + 0.1 * spectrum.x;
        float s = smoothstep(0.04, 0.0, abs(across)) * smoothstep(len, 0.0, abs(along)) * step(0.45, h);
        col += s * fade * 1.6 * mix(vec3(0.6, 0.8, 1.0), vec3(1.0, 0.7, 0.9), h);
    }
    col += vec3(0.05, 0.02, 0.12) * (1.0 - length(uv)) * (0.5 + spectrum.y);
    fragColor = vec4(col, 1.0);
}

More Starters examples

Kaleido pulse · Laser show · Metaballs · Oscilloscope trails · Strobe grid