Domain warping

glint · Examples · Tutorials · Gallery

Fractal noise fed back into itself twice (Inigo Quilez's domain warping): marbled, flowing, paint-like, coloured by the intermediate warps.

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

Domain warping: 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 vec2 mouse;
uniform vec3 spectrum;
uniform vec3 spectrumIntegrated;
uniform float beat;
uniform float warp;
uniform vec3 inkA;
uniform vec3 inkB;

in vec2 v_texcoord;
out vec4 fragColor;

float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
float noise(vec2 p) {
    vec2 i = floor(p), f = fract(p);
    vec2 u = f * f * (3.0 - 2.0 * f);
    return mix(mix(hash(i), hash(i + vec2(1, 0)), u.x), mix(hash(i + vec2(0, 1)), hash(i + vec2(1, 1)), u.x), u.y);
}
const mat2 M = mat2(0.8, 0.6, -0.6, 0.8);
float fbm(vec2 p) {
    float v = 0.0, a = 0.5;
    for (int i = 0; i < 6; i++) { v += a * noise(p); p = M * p * 2.02; a *= 0.5; }
    return v;
}

void main() {
    vec2 uv = (gl_FragCoord.xy - 0.5 * resolution) / resolution.y * 3.0;
    float t = time * 0.1 + spectrumIntegrated.x * 0.3;
    // f(p + f(p + f(p))): each fbm displaces the input of the next.
    vec2 q = vec2(fbm(uv + vec2(0.0, 0.0) + t), fbm(uv + vec2(5.2, 1.3) - t));
    vec2 r = vec2(fbm(uv + warp * q + vec2(1.7, 9.2) + 0.15 * t), fbm(uv + warp * q + vec2(8.3, 2.8) + 0.126 * t));
    float f = fbm(uv + warp * r);
    vec3 col = mix(inkA, inkB, clamp(f * f * 4.0, 0.0, 1.0));
    col = mix(col, vec3(0.0, 0.0, 0.16), clamp(length(q), 0.0, 1.0));
    col = mix(col, vec3(0.95, 0.9, 0.8), clamp(length(r.x), 0.0, 1.0) * 0.6);
    col *= 0.6 + 0.8 * f * f + beat * 0.2;
    fragColor = vec4(pow(col, vec3(0.8)), 1.0);
}

More Showpieces examples

Ocean · KIFS tunnel · Truchet weave · Voronoi crystals · Neon city · Galaxy · Fluid · GPU particles