Browse Source

Add a parameter for shapes to not drop shadow.

Godzil 4 years ago
parent
commit
b251b632ac
3 changed files with 13 additions and 7 deletions
  1. 1 0
      source/include/shape.h
  2. 1 0
      source/shapes/shape.cpp
  3. 11 7
      source/world.cpp

+ 1 - 0
source/include/shape.h

@@ -40,6 +40,7 @@ public:
     Matrix transformMatrix;
     Matrix inverseTransform;
     Material material;
+    bool dropShadow;
 
 public:
     Shape(ShapeType = SHAPE_NONE);

+ 1 - 0
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();

+ 11 - 7
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;
 }