diff --git a/source/include/shape.h b/source/include/shape.h index c536078..320a307 100644 --- a/source/include/shape.h +++ b/source/include/shape.h @@ -40,6 +40,7 @@ public: Matrix transformMatrix; Matrix inverseTransform; Material material; + bool dropShadow; public: Shape(ShapeType = SHAPE_NONE); diff --git a/source/shapes/shape.cpp b/source/shapes/shape.cpp index 8890a58..2744408 100644 --- a/source/shapes/shape.cpp +++ b/source/shapes/shape.cpp @@ -15,6 +15,7 @@ Shape::Shape(ShapeType type) { + this->dropShadow = true; this->type = type; this->transformMatrix = Matrix4().identity(); this->inverseTransform = this->transformMatrix.inverse(); diff --git a/source/world.cpp b/source/world.cpp index ca870f0..3e9ca81 100644 --- a/source/world.cpp +++ b/source/world.cpp @@ -94,7 +94,6 @@ Intersect World::intersect(Ray r) Tuple World::shadeHit(Computation comps, uint32_t depthCount) { - /* TODO: Add support for more than one light */ uint32_t lightIndex; Tuple surface = Colour(0, 0, 0); @@ -136,20 +135,25 @@ Tuple World::colourAt(Ray r, uint32_t depthCount) bool World::isShadowed(Tuple point, uint32_t light) { - /* TODO: Add support for more than one light */ - Tuple v = this->lightList[light]->position - point; double distance = v.magnitude(); Tuple direction = v.normalise(); Ray r = Ray(point, direction); - Intersection h = this->intersect(r).hit(); + Intersect xs = this->intersect(r); - if (!h.nothing() && (h.t < distance)) + int i; + for(i = 0; i < xs.count(); i++) { - return true; - } + Intersection h = xs[i]; + if (h.t < 0) continue; + + if ((h.object->dropShadow == true) && (h.t < distance)) + { + return true; + } + } return false; }