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


void main()
{
    vec3 eye = vec3(cos(u_time*2.),sin(u_time*2.),-10); //vec3(0,0,-10.000);
    vec3 up = vec3(0, 1, 0);
    vec3 right = vec3(1, 0, 0);

    //float u = gl_FragCoord.x * 2.0 / u_resolution.x - 1.0;//centered on 0 in a -1. ,1. range
    //float v = gl_FragCoord.y * 2.0 / u_resolution.y - 1.0;

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

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

    vec3 ro = eye + forward * eyeOffsetToPlane + right * u + up * v;//ray origin ???
    vec3 eyeOffset = eye*eyeOffsetToPlane;
    vec3 rd = normalize(eyeOffset-ro);//cross(right, up));// ray direction ? seem to take norm of perpendicular



    //ro += cos(u_time/2.);

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

    float t = 0.0;
    const int maxSteps = 32;
    float g_rmEpsilon = 0.036;

    float mergeFact = abs(cos(u_time))/10.;//nice variation to use to merge two shapes togther

    for(int i = 0; i < maxSteps; ++i)
    {
        vec3 p = ro + rd * t;
        float d = 0.;
        d= smin(
            sphere(p+vec3(0.154,0.415,0.371), 0.160),
            sphere(p+vec3(0.405,0.195,0.250), 0.380)  //length(p) - 0.5; // Distance to sphere of radius 0.5
        ,0.1);
        d = min(d, sdBox(p+vec3(0.044,0.570,0.001),vec3(0.433,1.000,-.0)));
        //d = min(d, sdCylinder(p+vec3(0.1), vec3(0.074,0.180,0.235)));



        if(d < g_rmEpsilon)
        {
            color = mix( vec4(colorGradient(i,maxSteps), 2.024), color, 0.868); // Sphere color
            //color = vec4(colorGradient(i, maxSteps),1.);
            color = color + vec4(colorGradient(i,maxSteps), 2.024)*0.01;
            break;
        }

        t += d;
    }


    gl_FragColor = vec4( color );
}

uniform vec2 u_mouse;
uniform float u_time;

const int maxSteps = 30;


float sphere(in vec3 p, float radius){
	return length(p) - radius; // Distance to sphere of radius r
