diff --git a/src/Geometry.cc b/src/Geometry.cc index 0a29ab8..c0c1437 100644 --- a/src/Geometry.cc +++ b/src/Geometry.cc @@ -10,6 +10,7 @@ float Geometry::coefDiffuse() const { return kd; } float Geometry::coefSpecular() const { return ks; } float Geometry::coefAmbient() const { return ka; } float Geometry::getPhong() const { return phong; } +Geometry::Type Geometry::getType() const { return type; } void Geometry::setTransform(const Matrix4f &transform) { this->transform = transform; diff --git a/src/Geometry.h b/src/Geometry.h index b3d1eee..d0cde58 100644 --- a/src/Geometry.h +++ b/src/Geometry.h @@ -41,6 +41,7 @@ public: float coefAmbient() const; float getPhong() const; void setTransform(const Matrix4f &); + Type getType() const; }; class Sphere : public Geometry { diff --git a/src/Light.cc b/src/Light.cc index 2b0030a..b2e4888 100644 --- a/src/Light.cc +++ b/src/Light.cc @@ -1,6 +1,7 @@ #include "Light.h" #include #include +#include void Light::setTransform(const Matrix4f &transform) { this->transform = transform; @@ -26,7 +27,8 @@ Vector3f PointLight::illumination(const HitRecord &hit, Ray shadowRay(shadingPoint, rayDirection); for (auto g : geometries) - if (g != geometry && g->intersect(shadowRay).hasValue()) + if (g != geometry && g->intersect(shadowRay).hasValue() && + g->getType() == Geometry::Type::SPHERE) return Vector3f::Zero(); Vector3f ambient_ = geometry->coefAmbient() * geometry->ambient(); @@ -55,9 +57,12 @@ Vector3f AreaLight::illumination(const HitRecord &hit, color += PointLight(*this, p1 + (u + v) / 2).illumination(hit, geometries); } else { for (int y = 0; y < gridSize; ++y) - for (int x = 0; x < gridSize; ++x) - color += PointLight(*this, p1 + (u * x + v * y) / gridSize) - .illumination(hit, geometries); + for (int x = 0; x < gridSize; ++x) { + Vector3f contribution = + PointLight(*this, p1 + (u * x + v * y) / gridSize) + .illumination(hit, geometries); + color += contribution; + } } return color / gridSize / gridSize;