#version 120

uniform float time;
uniform vec2 resolution;
uniform vec2 mouse;


#define iTime time
#define iResolution resolution


vec3 rDir(vec2 pixPos,
          vec2 viewSizes)
{
    vec3 dir = vec3(pixPos - (viewSizes * 0.5),
                	viewSizes.y / tan(1.62 * 0.5));
    return normalize(dir);
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    //float zOffs = sin(iTime * 1.5f)
    vec3 ro = vec3(0.35f, 1.15f, -10.5f);
    vec3 rd = rDir(fragCoord, iResolution.xy);
    float eps = 0.0001f;
    const float maxDist = 16.0f;
    float t = 1.0f;
    float dt = 0.0f;
    vec3 rgb = vec3(0.25f);
    float stepCtr = 0.0f; // Iteration counter for benchmarking
    float frq = 2.0f; // Sphere origins every four units
    float spacing = frq * 0.5f; // Two-unit spacing between spheres
    t = 0.0f;
    while (stepCtr < 64.0f)
    {
    	vec3 p = ro + rd * t;       
    	p = mod(p, vec3(frq)) - vec3(spacing);
    	dt = length(p - vec3(0,0,0)) - 0.5f;
    	if (dt < eps)
    	{
    	    rgb = vec3(stepCtr * 0.0025f) * (stepCtr * 0.1f);
    	    rgb = vec3(1.0) - rgb;
    		break; 
    	}
    	else
    	{ t += dt; }
    	stepCtr += 1.0f;
    }
    // Output to screen
    fragColor = vec4(rgb,1.0);
}

void main( void )
{
  vec4 color = vec4(0.0,0.0,0.0,1.0); 
  mainImage(color, gl_FragCoord.xy);
  gl_FragColor = color;
}  









