export default `#define MAX_STEPS 1280
#define MAX_DIST 1024.
#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);
}

int hash(ivec2 p) {
    return (p.x * 7919 + p.y) * 6563;
}

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

float pMod1(inout float p, float size)
{
    float halfsize = size * 0.5;
    float c = floor((p+halfsize) / size);
    p = mod(p + halfsize, size) - halfsize;
    return c;
}

vec3 pMod3(inout vec3 p, vec3 size)
{
    vec3 c;
    c.x = pMod1(p.x, size.x);
    c.y = pMod1(p.y, size.y);
    c.z = pMod1(p.z, size.z);
    return (c);
}

vec3 modlimSDF( 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 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 sdfSphere(vec3 p, float r)
{
    return length(p) - r;
}

float rand21(vec2 n) { 
	return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
}

float rand11(float n){return fract(sin(n) * 43758.5453123);}

float sdfCone( vec3 p, vec2 c, float h )
{
  float q = length(p.xz);
  return max(dot(c.xy,vec2(q,p.y)),-h-p.y);
}

float opSmoothUnion( float d1, float d2, float k )
{
	float abs = (d1-d2) > 0. ? d1-d2 : d2-d1;
    float h = max(k-abs,0.0);
    return min(d1, d2) - h*h*0.25/k;
}

// 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 Time = iTime / 2.;
    float sd1 = 2000.;
    float cd1 = 2000.;
    int ret = 0;
    vec2 cell;
    cell.x = pMod1(p.x, 5.);
    cell.y = pMod1(p.z, 5.);
    //p.y += mod(100. * iTime * rand11(cell.x) * rand11(cell.y), 100.) - 50.;
    //p.y += rand11(cell.x) * rand11(cell.y) * 100. - 50.;
    //p.y += mod(100. * iTime * 0.5, 100.) - 50.;
    float r21 = rand21(cell) * 10.;
    int sec = int(floor(mod(Time * 100., 10.)));
	int abso = int(mod(Time, 10.)) - 5;
	if (abso < 0)
		abso = -abso;
    if (int(floor(r21)) < 1 + abso && fract(r21) > abs(sin(Time / 3.)) - 0.3)
    {
        r21 -= 0.90;
        r21 *= 10.;
        p.y += sin(cell.x / 3. + sin(Time * 1.456) * PI) * 3. * sin(cell.y / 3. + sin(Time * 0.756) * PI) * 3.;
        pMod1(p.y, sin(Time * 1.234) * 20. + 70.);
        //p.z += 0.1 * (rand11(cell.y) - 0.5);
        //p.y += r21 * 100.;
        //p.y += iTime * 100. * r21;
        //p.y = mod(p.y, 200.) - 100.;
        //sd1 = sdfSphere(p, rand11(cell.x) * rand11(cell.y) * 1.4) * 0.1;
        sd1 = sdfSphere(p , 2.) * 0.05;
        //cd1 = sdfCone(p - vec3(0., 5.0, 0.), vec2(sin(PI/2.6), cos(PI/2.6 )), 4.) * 1.;
        ret = 1;
    }
   	
    //return min(sd1, cd1);
    if (ret == 1)
        //return min(sd1, cd1);
    	return opSmoothUnion(sd1, cd1, 0.2);
    return 1.;
}

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

vec3 normal(vec3 p)
{
    float d = scene(p);
    vec2 e = vec2(0.001, 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 n, vec3 ro)
{
    vec3 lightPos = vec3(-10. * sin(iTime * 2.), 10., -10. * cos(iTime * 2.)) + ro;// +  vec3(sin(iTime * 1.) * 1000.);
    vec3 l = normalize(lightPos - p);
    
    float dif = clamp(dot(l, n), 0., 1.);
    //vec2 d = march(p+n*E * 30., l);
    //if (d.x < 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(0., 30., 0.);
    vec3 rd = normalize(vec3(uv.x, uv.y, 1.));
    rd = rotX(rd, PI / 6.);
    rd = rotY(rd, iTime / 3.);
    ro.x += iTime * 10.;
	vec3 col = vec3(0);
    
    vec2 d = march(ro, rd);

    if (d.x > 0.)
    {
        vec3 p = ro + rd * d.x;
        vec3 n = normal(p);
        p += n * E * 10.;
        float dif = light(p, n, ro);
        col += vec3(0.6118 * dif, 0.7275 * dif, 0.9588 * dif);
        //61.18% red, 82.75% green and 85.88%
    }
    else
    {
        vec3 bb = blackbody(d.y * 3000.);
        bb = vec3(bb.z + bb.x / abs(sin(iTime / 3.)), bb.y + bb.x / abs(cos(iTime / 2.5)), bb.x);
        bb = vec3(bb.x / 2., bb.y / 2., bb.z);
        col += bb;
    }
    fragColor = vec4(col, 1.0);
}`;
