mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
finish global illumination
This commit is contained in:
parent
e59c6dbea4
commit
a63aedc323
5 changed files with 41 additions and 20 deletions
10
src/Light.cc
10
src/Light.cc
|
@ -22,6 +22,10 @@ bool Light::isUse() const { return use; }
|
|||
|
||||
Vector3f PointLight::getCenter() const { return center; }
|
||||
|
||||
bool lightOnSurface(Vector3f center, Geometry *g) {
|
||||
return (g->sample() - center).dot(g->normal(center)) < 1e-5;
|
||||
}
|
||||
|
||||
Vector3f PointLight::illumination(const HitRecord &hit,
|
||||
const vector<Geometry *> &geometries) const {
|
||||
Vector3f shadingPoint = hit.point();
|
||||
|
@ -30,9 +34,9 @@ Vector3f PointLight::illumination(const HitRecord &hit,
|
|||
Ray shadowRay(shadingPoint, rayDirection);
|
||||
|
||||
for (auto g : geometries)
|
||||
if (g != geometry && g->intersect(shadowRay).hasValue() &&
|
||||
g->type() == Geometry::Type::SPHERE)
|
||||
return Vector3f::Zero();
|
||||
if (g != geometry && g->intersect(shadowRay).hasValue())
|
||||
if (g->type() == Geometry::Type::SPHERE || !lightOnSurface(center, g))
|
||||
return Vector3f::Zero();
|
||||
|
||||
Vector3f ambient_ =
|
||||
geometry->ka() * geometry->ca().array() * Scene::current->ai().array();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue