Add shadows
This commit is contained in:
parent
c3d9698ede
commit
b3f073e2be
|
@ -24,7 +24,12 @@ public class RayTracerSimple extends RayTracer {
|
||||||
Color lightDiffuse = Color.BLACK; // The sum of diffuse contributions from all the lights
|
Color lightDiffuse = Color.BLACK; // The sum of diffuse contributions from all the lights
|
||||||
|
|
||||||
for (Light light : scene.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 lLSqr = l.lengthSquared(); // Distance from p to the light squared
|
||||||
double lL = Math.sqrt(lLSqr); // Distance from p to the light
|
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_
|
double cosLN = n_.dot(l) / lL; // Cosine of the angle between l and n_
|
||||||
|
|
Loading…
Reference in a new issue