     vec3 boxMin = vec3(-1.0, -1.0, -1.0);
     vec3 boxMax = vec3(1.0, 1.0, 1.0);
     float boxT = box(rayOrigin, rayDirection, boxMin, boxMax);
-    float boxDiffuse = diffuse(rayOrigin, rayDirection, boxT, light, boxNormal(rayOrigin, rayDirection, boxT, boxMin, boxMax));
+    vec3 boxIntersection = rayOrigin + rayDirection * boxT;
+    float boxDiffuse = diffuse(boxIntersection, light, boxNormal(boxIntersection, boxMin, boxMax));
 
     vec3 sphereCenter = vec3(0.0, 1.0, 0.0);
     float sphereRadius = 1.0;
     float sphereT = sphere(rayOrigin, rayDirection, sphereCenter, sphereRadius);
-    float sphereDiffuse = diffuse(rayOrigin, rayDirection, sphereT, light, sphereNormal(rayOrigin, rayDirection, sphereCenter, sphereT));
+    vec3 sphereIntersection = rayOrigin + rayDirection * sphereT;
+    float sphereDiffuse = diffuse(sphereIntersection, light, sphereNormal(sphereIntersection, sphereCenter));
 
     vec3 planeCenter = vec3(0.0, 0.0, 0.0);
     vec3 planeNorm = vec3(0.0, 1.0, 0.0);
     float planeT = plane(rayOrigin, rayDirection, planeCenter, planeNorm);
-    float planeDiffuse = diffuse(rayOrigin, rayDirection, planeT, light, planeNormal(planeNorm));
+    vec3 planeIntersection = rayOrigin + rayDirection * planeT;
+    float planeDiffuse = diffuse(planeIntersection, light, planeNormal(planeNorm));
 
     float minT = max_distance;
     vec4 color = vec4(0.0, 0.0, 0.0, 1.0);

    return normalize(planeDirection);
}

float diffuse(vec3 ro, vec3 rd, float t, vec3 light, vec3 normal) {
    vec3 intersection = ro + rd * t;
    vec3 direction = normalize(light - intersection);
    return max(0.0, dot(normal, direction));
}

    return min(t1, t2);
}

vec3 sphereNormal(vec3 intersection, vec3 sc) {
    return normalize(intersection - sc);
}

float plane(vec3 ro, vec3 rd, vec3 pc, vec3 pn) {
