0.00
60.0 fps

MandelShip

through the endless night...

Log in to post a comment.

#version 300 es
precision highp float;

#define MAX_ITER 16

uniform float iTime;
uniform vec2  iResolution;

out vec4 fragColor;

vec2 vpow2(vec2 v){
    return vec2(v.x * v.x - v.y * v.y, 2. * v.x * v.y);
}

vec2 rv(vec2 v, float r){
    float a = atan(v.y, v.x);
    a += r;
    return vec2(cos(a), sin(a)) * length(v);
}

vec3 fog(vec2 c, vec2 v){
    vec2 r = c - v;
    return vec3(.1, .1, .1) * max(0., 1. - 1. * length(r)) * (1. + .3 * sin(r.x * 7.) + .3 * sin(6. * r.y));
}

void main() {
    // Screen coordinate (from [-aspect, -1] to [aspect, 1])
    vec2 q   = (2. * gl_FragCoord.xy - iResolution) / iResolution.y;
    
    vec2 c = q * 1. + vec2(-0.5, 0.25);
    vec2 c2 = rv(c, 0.1 * sin(iTime)) + vec2(0., .15) * sin(iTime);
    vec2 z = vec2(0., 0.);
    
    int i = 0;
    
    while(length(z) < 1024. && i < 64){
        z = vpow2(z) + c2;
        i++;
    }
    
    float it = float(i) + 1. - log(log(length(z))) / log(2.);
    float mit = c.y * 46. + 3. * sin(c.x * 2.5 + iTime);

    // Pixel color
    vec3 col;
    if(it < mit){
        col = vec3(1., 1., 1.) * it / (64. - mit);
        //fog effect
        for(int i = 0; i < 64; i++){
            float sx = 2. + 1. * sin(float(i) * 2345.);
            float x = 3. * sin(1000. * float(i)) + 0.5 * sin(sx * iTime);
            float y = 4. * sin(1235. * float(i));
            col += fog(c, vec2(x, y));
        }
    }
    else{
        col = vec3(0., 0., 0.);
    }

    // Output
    fragColor = vec4(col, 1.);
}