export default `
#define MAX_STEPS 1280
#define MAX_DIST 128.
#define E 0.0001
#define PI 3.141592

vec3 rotX(vec3 v, float a)
{
    return vec3(v.x, v.y * cos(a) - v.z * sin(a), v.y * sin(a) + v.z * cos(a));
}

vec3 rotY(vec3 v, float a)
{
    return vec3(v.x * cos(a) + v.z * sin(a), v.y, v.z * cos(a) - v.x * sin(a));
}

vec3 rotZ(vec3 v, float a)
{
    return vec3(v.x * cos(a) - v.y * sin(a), v.x * sin(a) + v.y * cos(a), v.z);
}

vec3 modSDF(vec3 p, vec3 c)
{
    return mod(p + 0.5 * c, c) - 0.5 * c;
}

float sdfTorus(vec3 p, vec2 r)
{
    float x = length(p.xz) - r.x;
    return length(vec2(x, p.y)) - r.y;
}


// blackbody by aiekick : https://www.shadertoy.com/view/lttXDn

// -------------blackbody----------------- //

// return color from temperature
//http://www.physics.sfasu.edu/astro/color/blackbody.html
//http://www.vendian.org/mncharity/dir3/blackbody/
//http://www.vendian.org/mncharity/dir3/blackbody/UnstableURLs/bbr_color.html

vec3 blackbody(float Temp)
{
	vec3 col = vec3(255.);
    col.x = 56100000. * pow(Temp,(-3. / 2.)) + 148.;
   	col.y = 100.04 * log(Temp) - 623.6;
   	if (Temp > 6500.) col.y = 35200000. * pow(Temp,(-3. / 2.)) + 184.;
   	col.z = 194.18 * log(Temp) - 1448.6;
   	col = clamp(col, 0., 255.)/255.;
    if (Temp < 1000.) col *= Temp/1000.;
   	return col;
}

// -------------blackbody----------------- //


float scene(vec3 p)
{
    float td1 = sdfTorus(
        modSDF(
            rotX(
                p - vec3(3. + cos(p.x * 10. + iTime) / 3., sin(p.y * 10. + iTime) / 3., 6.),
                PI / 2.),
            vec3(6.)), vec2(2., abs(sin(iTime)) * 0.2 + 0.1)) * 0.1;
    float td2 = sdfTorus(
        modSDF(
            rotZ(
                rotX(
                    p - vec3(3. + cos(p.x * 10. + iTime) / 3., -3. + sin(p.y * 10. + iTime) / 3., 6.), PI / 2.), PI / 2.), vec3(6.)), vec2(2., abs(cos(iTime)) * 0.2 + 0.1))* 0.1;
    float td3 = sdfTorus(
        modSDF(
            rotZ(
                p - vec3(cos(p.x * 10. + iTime) / 3., sin(p.y * 10. + iTime) / 3., 3.), PI / 2.), vec3(6.)), vec2(2., abs(sin(iTime)) * 0.2 + 0.1))* 0.1;
    float td4 = sdfTorus(modSDF(p + vec3(cos(p.x * 10. + iTime) / 3., sin(p.y * 10. + iTime) / 3., -6.), vec3(6.)), vec2(2., abs(cos(iTime)) * 0.2 + 0.1))* 0.1;
    //float td2 = 10000.;
    float d = min(td1, td2);
    d = min(d, td3);
    d = min(d, td4);
    return d;
}

float march(vec3 ro, vec3 rd)
{
    float dO = 0.;

    for (int steps = 0; steps < MAX_STEPS; steps++)
    {
        vec3 p = ro + rd * dO;
        float dS = scene(p);
        dO += dS;
        if (dS < E || dO > MAX_DIST)
            break;
    }
    return dO;
}

vec3 normal(vec3 p)
{
    float d = scene(p);
    vec2 e = vec2(0.3, 0);

    vec3 n = d - vec3(
        		scene(p - e.xyy),
                scene(p - e.yxy),
                scene(p - e.yyx));
    return (normalize(n));
}

float light(vec3 p)
{
    vec3 lightPos = vec3(0., 0., 0.);
    vec3 l = normalize(lightPos - p);
    vec3 n = normal(p);

    float dif = clamp(dot(l, n), 0., 1.);
//    float d = march(p+n*E * 30., l);
//    if (d < length(lightPos - p))
//        	dif *= 0.1;
    return (dif);
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = ((fragCoord - .5 * iResolution.xy) / iResolution.y);

    vec3 ro = vec3(7., 7., iTime);
    vec3 rd = normalize(vec3(uv.x, uv.y, 1));
    rd = rotX(rd, iTime * 0.256);
    rd = rotY(rd, iTime * 0.314);
    rd = rotZ(rd, iTime * 0.1618);
    //rd = rotX(rd, PI / 2.);

    float d = march(ro, rd);

    vec3 p = ro + rd * d;
    float dif = light(p);
	vec3 col = vec3(dif);
    col = blackbody(d * 10.);
    col += vec3(abs(mod((p.x + sin(iTime))/ 10., 1.) - 0.5) * dif, abs(mod((p.y + sin(iTime)) / 10., 1.) - 0.5)  * dif, abs(mod((p.z + sin(iTime)) / 10., 1.) - 0.5)  * dif);
    // Output to screen
	col = pow(col, vec3(0.454545));
    fragColor = vec4(col, 1.0);
}`