 /*
 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
+
+This shadertoy is very usefull to understand some of the basics:
+https://www.shadertoy.com/view/XsB3Rm
+This article (and the links within it) as well
+http://9bitscience.blogspot.de/2013/07/raymarching-distance-fields_14.html
 */
 #ifdef GL_ES
 precision mediump float;

        depth += distance;

        if(depth >= far){
        	return 0.;
        }
    }


    return far;
}


vec3 rayDir(float fov, vec2 size, vec2 pos ) {
	vec2 xy = pos - size * 0.5;//negate, map to half space ? so instead of a point in 0.0,1.0

	float cot_half_fov = tan( ( 90.0 - fov * 0.5 ) * DEG_TO_RAD );
	float z = size.y * 0.5 * cot_half_fov;//half size along y times half fov to get z value

	return normalize( vec3( xy, -z ) );//normalize on 0,1
}

vec3 crapRayDir(vec2 size, vec2 pos, vec3 eye){

    vec3 right = vec3(1, 0, 0);
	vec3 up = vec3(0, 1, 0);

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

    float eyeOffsetToPlane = 0.624;
    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
	return rayDirection;
}


//color gradient between blue and red based on iteration
