export default `
#define MAX_STEPS 12800
#define MAX_DIST 128.
#define E 0.001
#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;
}

vec3 modSDFlim( in vec3 p, in float c, in vec3 l)
{
    return p-c*vec3(clamp(floor(p.x/c + 0.5),-l.x,l.x), clamp(floor(p.y/c + 0.5),-l.y,l.y), clamp(floor(p.z/c + 0.5),-l.z,l.z));
}

vec3 elongateSDF(in vec3 p, in vec3 h )
{
    vec3 q = abs(p)-h;
    return max(q,0.0) + min(max(q.x,max(q.y,q.z)), 0.0);
}

vec3 twistSDF(in vec3 p, float k )
{
    float c = cos(k*p.y);
    float s = sin(k*p.y);
    mat2  m = mat2(c,-s,s,c);
    vec3  q = vec3(m*p.xz,p.y);
    return q;
}

float sdfBox( vec3 p, vec3 b )
{
  vec3 q = abs(p) - b;
  return length(max(q,0.0)) + min(max(q.x,max(q.y,q.z)),0.0);
}

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

float sdfSphere(vec3 p, float r)
{
    return length(p) - r;
}

// 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----------------- //


vec2 scene(vec3 p)
{
    float d = 10000.;
    float sd1 = 10000.;
    //float td1 = sdfTorus(elongateSDF(
    //    twistSDF(
    //        rotX(p, PI / 2.), sin(iTime) * 1.5), vec3(1., 1.,sin(iTime) * 2. + 1.))
    //    , vec2(abs(sin(iTime * 0.3723)) * 2. + 1.2, 0.2))
    //                     + 0.1 * sin(p.x * 20.) * sin(p.y * 20.) * sin(p.z * 20.);
    float td1 = sdfTorus(
        twistSDF(
            rotX(p, PI / 2.), sin(iTime) * 1.5)
        , vec2(abs(sin(iTime * 0.3723)) * 2. + 1.2, 0.2))
                         + 0.1 * sin(p.x * 20.) * sin(p.y * 20.) * sin(p.z * 20.);
    //float td1 = 10000.;
    //float td2 = sdfTorus(twistSDF(rotX(p, PI / 2.), cos(iTime) * 3.), vec2(abs(sin(iTime * 0.3723)) * 1. + 0.2, 0.1))
    //                     + 0.1 * sin(p.x * 20.) * sin(p.y * 20.) * sin(p.z * 20.);
    float td2 = 10000.;
    td2 = sdfTorus(
        twistSDF(
            rotX(p, PI / 2.), cos(iTime) * 1.5)
        , vec2(abs(sin(iTime * 0.3723)) * 2. + 2.2, 0.2))
                         + 0.1 * sin(p.x * 20.) * sin(p.y * 20.) * sin(p.z * 20.);
    //float td1 = 10000.;
    sd1 = sdfSphere(p - vec3(0.,0.,0.),abs(sin(iTime * 0.3723)) * 2. + 0.4) * 0.19;
    
    
    td1 *= 0.2;
    td2 *= 0.2;
    d = min(td1, d);
    d = min(td2, d);
    d = min(sd1, d);
    if (sd1 > d - E && sd1 < d + E)
   		return vec2(d, 1.);
    if ((td1 > d - E && td1 < d + E) || (td2 > d - E && td2 < d + E))
    	return vec2(d, 2.);
    return vec2(d, -1.);
}


vec3 march(vec3 ro, vec3 rd)
{
    float dO = 0.;
    float mind = 10000.;
    float object = -1.;
    for (int steps = 0; steps < MAX_STEPS; steps++)
    {
        vec3 p = ro + rd * dO;
        vec2 dS = scene(p);
        object = dS.y;
        if (dS.x < mind)
            mind = dS.x;
        dO += dS.x;
        if (dS.x < E || dO > MAX_DIST)
            break;
    }
    return vec3(dO, mind, object);
}

vec3 normal(vec3 p)
{
    vec2 d = scene(p);
    vec2 e = vec2(0.0001, 0);
    
    vec3 n = d.x - vec3(
        		scene(p - e.xyy).x,
                scene(p - e.yxy).x,
                scene(p - e.yyx).x);
    return (normalize(n));
}

float light(vec3 p, vec3 n)
{
    vec3 lightPos = vec3(-12. * sin(iTime), 0., -12. * cos(iTime));
    vec3 l = normalize(lightPos - p);
    
    float dif = clamp(dot(l, n), 0., 1.);
    vec3 d = march(p+n, l);
    if (d.x < length(lightPos - p))
        	dif *= 0.1;
    
    return (dif);
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
	vec3 col = vec3(0);
    vec2 uv = ((fragCoord - .5 * iResolution.xy) / iResolution.y);
    vec3 ro = vec3(-12. * sin(iTime), 0., -12. * cos(iTime));
    vec3 rd = normalize(vec3(uv.x, uv.y, 1.));
    rd = rotY(rd, iTime);
    
    vec3 d = march(ro, rd);
    
    vec3 p = ro + rd * d.x;
    vec3 n = normal(p);
    p += n * E * 10.;
    float dif = light(p, n);
    if (d.z > 1. + E || d.z < 1. - E)
    	col = blackbody(d.y * 10000.);
    if (d.x < MAX_DIST * 0.9)
    {
        if (d.z > 2. - E && d.z < 2. +E)
    		col +=  vec3(dif * abs(p.x - 0.5), dif * abs(p.y - 0.5), dif * abs(p.z - 0.5));

    	vec3 rr = rd - (2. * n * (dot(rd, n)));
    	vec3  d2 = march(p, rr);
    	vec3 p2 = p + rr * d2.x;
        vec3 n2 = normal(p2);
    	dif = light(p2, n2);
        if (d.z > 1. - E && d.z < 1. + E)
        {
    	  col += vec3(dif * abs(p2.x - 0.5), dif * abs(p2.y - 0.5), dif * abs(p2.z - 0.5));
        }
    }
    col = pow(col, vec3(0.454545));
    fragColor = vec4(col, 1.);
}
`