 float energySum(in vec3 position)
 {
     float energySum = 0.0f;
-    for(int i = 0; i <= SIZE - 1; i++)
+    for(int i = 0; i < SIZE; ++i)
     {
 //        if(sphereHit[i] == 1)
             energySum += energy(position, i);

    int sphere;
    Ray marchingRay = ray;

    currentStep = 0.1;
    int steps = 0;
    for(int i = 0; i < 40 && marchedDistance <= tmax; i++)
    {
//        countHits(marchingRay.origin);
//        nearestDistance(marchingRay.origin, currentStep);

        marchedDistance += currentStep;
//        countHits(marchingRay.origin);
        steps++;
        nrj = energySum(marchingRay.origin);
        if(nrj > 0.5f)
            break;
    }

    currentStep = 0.01;
//
//    if(nrj > 0.5)
//        direction = -1;
//    else
        direction = 1;

    for(int i = 0; i < 1 ; i++)
    {
        nearestDistance(marchingRay.origin, currentStep);
        marchingRay.origin += currentStep * marchingRay.direction * direction;
        marchedDistance += currentStep;
        steps++;
        if(energySum(marchingRay.origin) > 1.0f)
            break;
    }


    normal = vec3(energySum(marchingRay.origin));
    if(steps == 39)
    {
        return false;
    }
    return true;

}

// Task_5_3 - ToDo End
