 vec3 colorize(Hit hit, vec3 n, vec3 dir, const in vec3 lightPos)
 {
 	float diffuse = 0.3*max(0.0, dot(n, lightPos));
-	
+
 	vec3 ref = normalize(reflect(dir, n));
 	float specular = 0.4*pow(max(0.0, dot(ref, lightPos)), 6.5);
 
-	return (hit.color.rgb + 
+	return (hit.color.rgb +
 			diffuse * vec3(0.9) +
 			specular * vec3(1.0));
 }
 
-void mainImage( out vec4 fragColor, in vec2 fragCoord ) 
-{
-    //time = iGlobalTime;
-    glow = max(0.0, min(1.0, 2.0*sin(iGlobalTime*0.7-5.0)));
-    bite = smoothstep(0.0, 1.0, 1.6*sin(iGlobalTime*0.7));
-    sphere_col = SPHERE_COL*glow;
-
-    
-    vec2 pos = (fragCoord.xy*2.0 - resolution.xy) / resolution.y;
-	
+void mainImage( out vec4 fragColor, in vec2 fragCoord )
+{
+	//time = iGlobalTime;
+	glow = max(0.0, min(1.0, 2.0*sin(iGlobalTime*0.7-5.0)));
+	bite = smoothstep(0.0, 1.0, 1.6*sin(iGlobalTime*0.7));
+	sphere_col = SPHERE_COL*glow;
+
+
+	vec2 pos = (fragCoord.xy*2.0 - resolution.xy) / resolution.y;
+
 	float d = clamp(1.5*sin(0.3*iGlobalTime), 0.5, 1.0);
 	vec3 cp = vec3(10.0*d, -2.3*d, -6.2*d+4.0*clamp(2.0*sin(iGlobalTime*0.5), 0.0, 1.0)); // anim curious spectator
-	
+
 	if (mouse.z > 0.5)
 	{
 		vec2 mrel = mouse.xy/resolution.xy-0.5;
 		float mdis = (8.0+6.0*mrel.y);
 		cp = vec3(mdis*cos(-mrel.x*pih), 4.0*mrel.y, mdis*sin(-mrel.x*pih));
 	}
-	
-    vec3 ct = vec3(0.0, 0.0, 0.0);
-   	vec3 cd = normalize(ct-cp);
-    vec3 cu  = vec3(0.0, 1.0, 0.0);
-    vec3 cs = cross(cd, cu);
-    vec3 dir = normalize(cs*pos.x + cu*pos.y + cd*focus);	
-	
-    Hit h;
+
+	vec3 ct = vec3(0.0, 0.0, 0.0);
+	vec3 cd = normalize(ct-cp);
+	vec3 cu  = vec3(0.0, 1.0, 0.0);
+	vec3 cs = cross(cd, cu);
+	vec3 dir = normalize(cs*pos.x + cu*pos.y + cd*focus);
+
+	Hit h;
 	vec3 col = vec3(0.16);
 	vec3 ray = cp;
 	float dist = 0.0;
-	
+
 	// raymarch scene
-    for(int i=0; i < 60; i++) 
-	{
-        h = scene(ray);
-		
+	for(int i=0; i < 60; i++)
+	{
+		h = scene(ray);
+
 		if(h.d < 0.0001) break;
-		
+
 		dist += h.d;
 		ray += dir * h.d * 0.9;
 
-        if(dist > far) 
-		{ 
-			dist = far; 
-			break; 
+		if(dist > far)
+		{
+			dist = far;
+			break;
 		}
-    }
+	}
 
 	float m = (1.0 - dist/far);
 	vec3 n = normal(ray);
 	col = colorize(h, n, dir, sun)*m;
 
-    #ifdef EDGES
+	#ifdef EDGES
 	float edge = edges(ray);
 	col = mix(col, vec3(0.0), h.edge*edge*smoothstep(0.3, 0.35, length(ray)));
-    #endif
-    
+	#endif
+
 	vec3 neb = nebula(n);
 	col += min(glow, 0.1)*neb.brg;
-	
+
 	// HARD SHADOW with low number of rm iterations (from obj to sun)
 	#ifdef HARD_SHADOW
 	vec3 ray1 = ray;
 	dir = normalize(SUN_POS - ray1);
 	ray1 += n*0.002;
-	
+
 	float sunDist = length(SUN_POS-ray1);
 	dist = 0.0;
-	
-	for(int i=0; i < 35; i++) 
+
+	for(int i=0; i < 35; i++)
 	{
 		h = scene(ray1 + dir*dist);
 		dist += h.d;

	d1 = sdBox(q, vec3(0.1, 0.48, 0.48));
	if (d1 < d) { d = d1; col = vec3(0.1); }
	#endif
	
	return Hit(d, col, e);
}


#define pi2 6.283185307179586476925286766559
#define pih 1.5707963267949

// Using the nebula function of the "Star map shader" by morgan3d
// as environment map and light sphere texture (https://www.shadertoy.com/view/4sBXzG)
const float pi= 3.1415927;const int NUM_OCTAVES = 4;float hash(float n) { return fract(sin(n) * 1e4); } float hash(vec2 p){return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 +p.x))));}float noise(float x) { float i = floor(x);float f = fract(x); float u = f * f * (3.0 - 2.0 * f);return mix(hash(i),hash(i+1.0),u);}float noise(vec2 x){vec2 i=floor(x);vec2 f=fract(x);	float a = hash(i); float b=hash(i + vec2(1.0,0.0));float c=hash(i+vec2(0.0, 1.0)); float d = hash(i + vec2(1.0, 1.0)); vec2 u = f * f * (3.0 - 2.0 * f); return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y; }float NOISE(vec2 x){ float v = 0.0; float a = 0.5; vec2 shift=vec2(100);mat2 rot=mat2(cos(0.5),sin(0.5), -sin(0.5), cos(0.50)); for (int i = 0; i < NUM_OCTAVES;++i) {v+=a*noise(x);x = rot* x * 2.0 + shift; a *= 0.5; } return v; }float square(float x) { return x * x;}mat3 rotation(float yaw, float pitch){return mat3(cos(yaw),0,-sin(yaw), 0, 1, 0, sin(yaw), 0, cos(yaw)) * mat3(1, 0, 0, 0, cos(pitch), sin(pitch), 0, -sin(pitch), cos(pitch)); }vec3 nebula(vec3 dir) { float purple = abs(dir.x); float yellow = noise(dir.y);vec3 streakyHue = vec3(purple + yellow, yellow * 0.7, purple);vec3 puffyHue = vec3(0.8, 0.1, 1.0);float streaky = min(1.0, 8.0 * pow(NOISE(dir.yz*square(dir.x) * 13.0+ dir.xy * square(dir.z) * 7.0 + vec2(150.0, 2.0)),10.0));float puffy=square(NOISE(dir.xz * 4.0 + vec2(30, 10)) * dir.y);
return pow(clamp(puffyHue * puffy * (1.0 - streaky) + streaky * streakyHue, 0.0, 1.0), vec3(1.0/2.2));}
// ---

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