 // Title:
 /*
 disclaimer : this is not meant to be good code, but a learning process for me
-going 'back to basic' and learning all about the needed maths, logic, etc 
+going 'back to basic' and learning all about the needed maths, logic, etc
 */
 #ifdef GL_ES
 precision mediump float;

float sdBox( in vec3 p, vec3 b )
{
  	vec3 d = abs(p) - b;//absolute distance to point - bounds
	  //max(d.y,d.z) => what is bigger , dimension along y or z
  	//max(d.x, max(d.y,d.z) => what is bigger dimension along x, y or z
    //min(XX, 0.0) => what is smaller the above or 0 ? ie what is closest to the point
    //length(max(d,0.0)) => what is the length of biggest between 0 & the distance
    return min(max(d.x, max(d.y,d.z)),0.0) + //
         length(max(d,0.0));
}



void main()
{
    vec3 eye =  vec3(0.,0.,100.0);//vec3(cos(u_time*2.),sin(u_time*2.),-10);
    vec3 up = vec3(0, 1, 0);
    vec3 right = vec3(1, 0, 0);
	float near = 0.0;
    float far = 1000.0;

    vec2 uv =  (gl_FragCoord.xy * 2.0 / u_resolution) - 1.0;//centered on 0 in a -1. ,1. range

    float eyeOffsetToPlane = 0.360;
    vec3 forward = vec3(0,0,1.);

    vec3 rayOrigin = eye + forward * eyeOffsetToPlane + right * uv.x + up * uv.y;//ray origin ???
    vec3 eyeOffset = eye*eyeOffsetToPlane;
    vec3 rayDirection = normalize(eyeOffset-rayOrigin);//cross(right, up));// ray direction ? seem to take norm of perpendicular

    vec4 color = vec4(0.4); // Sky color

	float depth = rayMarch(rayOrigin, rayDirection, near, far);

    //vec3 pos = eye + rayDirection * depth;
    //vec3 norm = lightShade(ro, pos);
    color = vec4(vec3(depth),1.);

    gl_FragColor = color;
}
