Add shadows

This commit is contained in:
Petar Kapriš 2022-12-20 13:49:14 +01:00 committed by Петар Каприш
parent c3d9698ede
commit b3f073e2be

View file

@ -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_