Add a parameter for shapes to not drop shadow.

This commit is contained in:
Godzil
2020-02-22 17:38:25 +00:00
parent 81e323fdf4
commit b251b632ac
3 changed files with 13 additions and 7 deletions

View File

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

View File

@@ -15,6 +15,7 @@
Shape::Shape(ShapeType type)
{
this->dropShadow = true;
this->type = type;
this->transformMatrix = Matrix4().identity();
this->inverseTransform = this->transformMatrix.inverse();

View File

@@ -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++)
{
Intersection h = xs[i];
if (h.t < 0) continue;
if ((h.object->dropShadow == true) && (h.t < distance))
{
return true;
}
}
return false;
}