 	for(int i = 0; i < SIZE; ++i)
 	{
 		ivec2 uv = ivec2(i % 4, i / 4);
-	
+
 		vec4 v = texelFetch(positions, uv, 0);
-		
+
 		Sphere blob;
 		blob.position = v.xyz;
 		blob.radius = v.w;
 
 		blobs[i] = blob;
-		
+
 		Material mat;
 		mat.sr = texelFetch(materials0, uv, 0);
 		mat.dr = texelFetch(materials1, uv, 0);
-		
+
 		materials[i] = mat;
 	}
 }

	{
		float t0; // = ?
		float t1; // = ?
	
		// ...

		if(intersect(blobs[i], ray, t0, t1) /* todo, more? */)
		{
			// t = ?;
			// normal = ?;
			// Task 5_2: material = ?;
		}
	}
	return false; // ? 
	
	// ToDo: End Task 5_1
}


	// hint: use ray.origin, ray.direction, blob.position, blob.radius
	// hint: make it fast (if you like)! ;)

	vec3 rayNormal;
	float distanceToNormal;


    {
        vec3 r = ray.direction;
        vec3 s = ray.origin;
        vec3 c = blob.position;

        distanceToNormal = - (r.x * (s.x - c.x) + r.y * (s.y - c.y) + r.z * (s.z - c.z))/(pow(2, r.x) + pow(2, r.x) + pow(2, r.z));
    }

	rayNormal = blob.position - ray.origin - distanceToNormal * normalize(ray.direction);

	if(length(rayNormal) < blob.radius)
    {
        t0 = length((blob.position - rayNormal) - normalize(ray.direction) * sqrt(pow(blob.radius, 2.0) - pow(length(rayNormal), 2.0)));
        t1 = length((blob.position - rayNormal) + normalize(ray.direction) * sqrt(pow(blob.radius, 2.0) - pow(length(rayNormal), 2.0)));
        return true;
    }
	// Task_5_1 - ToDo End
	return false;
}

bool rcast(in Ray ray, out vec3 normal, out Material material, out float t)
{
    // Task_5_1 - ToDo Begin

	// return normal for the nearest intersected sphere, as well as
	// the intersection parameter t (that should allow to retrieve the
	// itnersection point I = ray.origin + ray.direction * t).

	// the function should return true, if at least one sphere was hit,
	// and false if no when no sphere was hit.

	// (Task_5_2 - ToDo return material of nearest intersected sphere)

	t =  INFINITY;
