mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
fix cornellbox
This commit is contained in:
parent
c9919e5b03
commit
13fc1a9576
3 changed files with 11 additions and 4 deletions
|
@ -10,6 +10,7 @@ float Geometry::coefDiffuse() const { return kd; }
|
||||||
float Geometry::coefSpecular() const { return ks; }
|
float Geometry::coefSpecular() const { return ks; }
|
||||||
float Geometry::coefAmbient() const { return ka; }
|
float Geometry::coefAmbient() const { return ka; }
|
||||||
float Geometry::getPhong() const { return phong; }
|
float Geometry::getPhong() const { return phong; }
|
||||||
|
Geometry::Type Geometry::getType() const { return type; }
|
||||||
|
|
||||||
void Geometry::setTransform(const Matrix4f &transform) {
|
void Geometry::setTransform(const Matrix4f &transform) {
|
||||||
this->transform = transform;
|
this->transform = transform;
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
float coefAmbient() const;
|
float coefAmbient() const;
|
||||||
float getPhong() const;
|
float getPhong() const;
|
||||||
void setTransform(const Matrix4f &);
|
void setTransform(const Matrix4f &);
|
||||||
|
Type getType() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Sphere : public Geometry {
|
class Sphere : public Geometry {
|
||||||
|
|
13
src/Light.cc
13
src/Light.cc
|
@ -1,6 +1,7 @@
|
||||||
#include "Light.h"
|
#include "Light.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
void Light::setTransform(const Matrix4f &transform) {
|
void Light::setTransform(const Matrix4f &transform) {
|
||||||
this->transform = transform;
|
this->transform = transform;
|
||||||
|
@ -26,7 +27,8 @@ Vector3f PointLight::illumination(const HitRecord &hit,
|
||||||
Ray shadowRay(shadingPoint, rayDirection);
|
Ray shadowRay(shadingPoint, rayDirection);
|
||||||
|
|
||||||
for (auto g : geometries)
|
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();
|
return Vector3f::Zero();
|
||||||
|
|
||||||
Vector3f ambient_ = geometry->coefAmbient() * geometry->ambient();
|
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);
|
color += PointLight(*this, p1 + (u + v) / 2).illumination(hit, geometries);
|
||||||
} else {
|
} else {
|
||||||
for (int y = 0; y < gridSize; ++y)
|
for (int y = 0; y < gridSize; ++y)
|
||||||
for (int x = 0; x < gridSize; ++x)
|
for (int x = 0; x < gridSize; ++x) {
|
||||||
color += PointLight(*this, p1 + (u * x + v * y) / gridSize)
|
Vector3f contribution =
|
||||||
.illumination(hit, geometries);
|
PointLight(*this, p1 + (u * x + v * y) / gridSize)
|
||||||
|
.illumination(hit, geometries);
|
||||||
|
color += contribution;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return color / gridSize / gridSize;
|
return color / gridSize / gridSize;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue