vec3 palette(float t) {
    // The factor 2.0 increases the color intensity.
    return mix(2.0 * vec3(0.2, 0.7, 0.9), 2.0 * vec3(1., 0., 1.), t);
}

vec2 rotate(vec2 p, float a) {
    float c = cos(a);
    float s = sin(a);
    return p*mat2(c, -s, s, c);
}

float map(vec3 p) {
    for( int i = 0; i<6; ++i){
        float t = iTime*0.2;
        p.xz =rotate(p.xz,t);
        p.xy =rotate(p.xy,t*1.89);
        p = abs(p) - 0.4;
    }
    return length(p);
}

vec4 rm(vec3 ro, vec3 rd) {
    float t = 0.;
    vec3 col = vec3(0.);
    float d;
    for(float i =0.; i<64.; i++){
		vec3 p = ro + rd*t;
        d = map(p)*.5;
        if(d<0.02){
            break;
        }
        if(d>100.){
        	break;
        }
        // The factor 1.5 increases the color intensity in the rendered object.
        col+= 1.8 * palette(length(p)*.1)/(500.*(d));
        t+=d;
    }
    return vec4(col,2./(d*100.));
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = (fragCoord-(iResolution.xy/2.))/iResolution.x;
	vec3 ro = vec3(0.,0.,-50.);
    ro.xz = rotate(ro.xz,iTime);
    vec3 cf = normalize(-ro);
    vec3 cs = normalize(cross(cf,vec3(0.,1.,0.)));
    vec3 cu = normalize(cross(cf,cs));
    vec3 uuv = ro+cf*3. + uv.x*cs + uv.y*cu;
    vec3 rd = normalize(uuv-ro);
    vec4 col = rm(ro,rd);
    fragColor = col;
}
