 
 	// Try to intersect with the spheres;
 	float closestIntersection = FLT_MAX;
+	float3 normal;
 	for (uint i = 0; i < numSpheres; ++i) {
-		float intersection = TestRaySphereIntersection(ray, spheres[i]);
-		if (intersection > 0.0f) {
-			closestIntersection = min(closestIntersection, intersection);
+		float3 newNormal;
+		float intersection = TestRaySphereIntersection(ray, spheres[i], newNormal);
+		if (intersection > 0.0f && intersection < closestIntersection) {
+			closestIntersection = intersection;
+			normal = newNormal;
 		}
 	}
 
-	float pixelColor;
-	if (closestIntersection == FLT_MAX) {
-		pixelColor = 0.0f;
+	float3 pixelColor;
+	if (closestIntersection < FLT_MAX) {
+		float attentuation = max(dot(normal, make_float3(0.70710678118f, 0.70710678118f, -0.70710678118f)), 0.0f);
+		pixelColor = make_float3(0.846, 0.933, 0.949) * attentuation + make_float3(0.15f, 0.15f, 0.15f);
 	} else {
-		pixelColor = 1.0f - (closestIntersection * 0.05f);
+		pixelColor = make_float3(0.0f, 0.0f, 0.0f);
 	}
 
 	if (x < width && y < height) {

    float secondIntersection = projectedRay + thc;

	float nearestIntersection;
	if (firstIntersection > 0 && secondIntersection > 0) {
		// Two intersections
		// Return the nearest of the two
		nearestIntersection = min(firstIntersection, secondIntersection);
	} else {
		// Ray starts inside the sphere
		// Return the far side of the sphere
		nearestIntersection = max(firstIntersection, secondIntersection);
	}

	return nearestIntersection;
}

		float *pixel = (float *)(textureData + y * pitch) + 4 /*RGBA*/ * x;

		// Write out pixel data
		pixel[0] += pixelColor.x;
		pixel[1] += pixelColor.y;
		pixel[2] += pixelColor.z;
		// Ignore alpha, since it's hardcoded to 1.0f in the display
		// We have to use a RGBA format since CUDA-DirectX interop doesn't support R32G32B32_FLOAT
	}
}
