Burning ship

glint · Examples · Tutorials · Gallery

The Mandelbrot formula with absolute values taken before squaring. That one change breaks the symmetry and grows a burning ship with its rigging, which the camera slowly zooms into.

Burning ship: a 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;

in vec2 v_texcoord;
out vec4 fragColor;

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(float n) { return fract(sin(vec2(n * 127.1, n * 269.5)) * 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))); }

void main() {
    vec2 uv = (gl_FragCoord.xy - 0.5 * resolution) / resolution.y;
    // From the whole set down to the ship and back out, over a minute.
    float into = 0.5 - 0.5 * cos(time * 0.1);
    float zoom = exp(-3.6 * into);
    vec2 centre = mix(vec2(-0.5, -0.45), vec2(-1.762, -0.035), smoothstep(0.0, 0.5, into));
    vec2 c = centre + uv * 2.2 * zoom * vec2(1.0, -1.0);
    vec2 z = vec2(0.0);
    float n = 0.0;
    for (int i = 0; i < 200; i++) {
        z = abs(z);
        z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c;
        if (dot(z, z) > 256.0) break;
        n += 1.0;
    }
    vec3 col = vec3(0.0);
    if (n < 200.0) {
        float s = n - log2(log2(dot(z, z))) + 4.0;                    // smooth count
        float t = sqrt(s / 200.0);
        col = vec3(1.0, 0.5, 0.1) * pow(t, 0.6) + vec3(1.0, 0.9, 0.5) * pow(t, 3.0);
        col *= 0.5 + 0.5 * cos(s * 0.15 + vec3(0.0, 0.4, 0.8)) * 0.3 + 0.35;
    }
    fragColor = vec4(col, 1.0);
}

More More GLSL examples

Pong · Jellyfish · Fireflies · Newton fractal · Perfect loop · Piano overlay · Listening piano