diff --git a/src/xyz/marsavic/gfxlab/graphics3d/raytracers/RayTracerSimple.java b/src/xyz/marsavic/gfxlab/graphics3d/raytracers/RayTracerSimple.java index 9e65de6..c279d2c 100644 --- a/src/xyz/marsavic/gfxlab/graphics3d/raytracers/RayTracerSimple.java +++ b/src/xyz/marsavic/gfxlab/graphics3d/raytracers/RayTracerSimple.java @@ -24,7 +24,12 @@ public class RayTracerSimple extends RayTracer { Color lightDiffuse = Color.BLACK; // The sum of diffuse contributions from all the lights for (Light light : scene.lights()) { - Vec3 l = light.p().sub(p); // Vector from p to the light; + Vec3 l = light.p().sub(p); // Vector from p to the light; + Ray lRay = new Ray(light.p(), l.inverse()); // Project a Ray from light source to object + Hit lHit = scene.solid().firstHit(lRay); + double epsilon = 0.000001; + if (lRay.at(Hit.t(lHit)).sub(p).lengthSquared() >= epsilon) + continue; // if it strikes an object before our point, a shadow is cast, no light is added double lLSqr = l.lengthSquared(); // Distance from p to the light squared double lL = Math.sqrt(lLSqr); // Distance from p to the light double cosLN = n_.dot(l) / lL; // Cosine of the angle between l and n_