 		PendingRay r = pendingRays[--numPendingRays];
 		
         Intersection s = sphereIntersect(r.ray);
-        if(s.object == -1) break;
-
-		float reflect_weight, refract_weight;
+        if(s.object == -1) continue;
+
+        color.rgb += r.weight * spheres[s.object].emission;
         vec3 point = r.ray.origin + r.ray.direction * s.distance;
-        vec3 shadedColor =
-            shade(spheres[s.object].shader, spheres[s.object].color, point,
-                  s.normal, reflect_weight, refract_weight);
-
-		if(reflect_weight > 0 && r.depth < 4){
-			vec3 rr = reflect(r.ray.direction, s.normal);
-            pendingRays[numPendingRays++] = PendingRay(
-                Ray(point, rr), reflect_weight * r.weight, r.depth + 1);
-        }
-		if(refract_weight > 0 && r.depth < 4){
-			vec3 rr = refract(r.ray.direction, s.normal, 1.0 / 1.5);
-            pendingRays[numPendingRays++] = PendingRay(
-                Ray(point, rr), refract_weight * r.weight, r.depth + 1);
-        }
+
 		
-        color.rgb += r.weight * shadedColor;
+        if(r.depth > 4){
+            // for(int i = 0; i < numSpheres; i++) {
+            //     if(spheres[i].emission == vec3(0)) continue;
+				
+            //     vec3 d = randomDirection();
+            //     d *= -sign(dot(d, spheres[i].position - point));
+
+            //     vec3 target = spheres[i].position + spheres[i].radius * d;
+            //     vec3 lightOffset = target - point;
+            //     vec3 lightDirection = normalize(lightOffset);
+            //     Ray shadowRay =
+            //         Ray(point + 0.01 * lightDirection, lightDirection);
+            //     Intersection shadow = sphereIntersect(shadowRay);
+
+            //     if(shadow.object == -1 ||
+            //        shadow.distance * shadow.distance >
+            //            dot(lightOffset, lightOffset)) {
+            //         color.rgb += r.weight * dot(s.normal, lightDirection);
+            //     }
+			// }
+			continue;
+        }
+
+		
+        if(spheres[s.object].shader == DIFFUSE_SHADER) {
+            vec3 rr = randomDirection();
+            rr *= sign(sign(dot(rr, s.normal)) + 0.5);
+            pendingRays[numPendingRays++] =
+                PendingRay(Ray(point, rr), r.weight * spheres[s.object].color,
+                           r.depth + 1);
+        } else if(spheres[s.object].shader == MIRROR_SHADER) {
+            vec3 rr = reflect(r.ray.direction, s.normal);
+            pendingRays[numPendingRays++] =
+                PendingRay(Ray(point, rr), r.weight, r.depth + 1);
+        }
+        // if(refract_weight > 0 && r.depth < 4){
+        // 	vec3 rr = refract(r.ray.direction, s.normal, 1.0 / 1.5);
+        //     pendingRays[numPendingRays++] = PendingRay(
+        //         Ray(point, rr), refract_weight * r.weight, r.depth + 1);
+        // }
     }
 
     // Average color with past samples from the same pixel

        
	return uintBitsToFloat( h ) - 1.0; 
}
vec3 randomPointOnSphere(){
	vec2 rand = vec2(random(), random());
	float theta = 2 * 3.14159 * rand.x;
	float u = 2*rand.y - 1;

                             (windowSize.y / 2));

    // Initialize view
    vec3 eye = vec3(0.0, 0.0, 49.9);
	//    vec3 target = vec3(position.x, position.y + 1, 0);
    Ray initialRay = Ray(eye, normalize(vec3(position.xy, -1)));

