fix cornellbox

This commit is contained in:
Shuo Feng 2024-03-14 17:43:59 -04:00
parent c9919e5b03
commit 13fc1a9576
Signed by: sfeng
GPG key ID: 1E83AE6CD1C037B1
3 changed files with 11 additions and 4 deletions

View file

@ -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;

View file

@ -41,6 +41,7 @@ public:
float coefAmbient() const;
float getPhong() const;
void setTransform(const Matrix4f &);
Type getType() const;
};
class Sphere : public Geometry {

View file

@ -1,6 +1,7 @@
#include "Light.h"
#include <algorithm>
#include <cmath>
#include <iostream>
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;