add ambient intensity

This commit is contained in:
Shuo Feng 2024-03-14 19:15:16 -04:00
parent ef5df2fa64
commit 641b62ca01
Signed by: sfeng
GPG key ID: 1E83AE6CD1C037B1
4 changed files with 13 additions and 2 deletions

View file

@ -1,4 +1,6 @@
#include "Light.h" #include "Light.h"
#include "Scene.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
@ -30,7 +32,8 @@ Vector3f PointLight::illumination(const HitRecord &hit,
g->type() == Geometry::Type::SPHERE) g->type() == Geometry::Type::SPHERE)
return Vector3f::Zero(); return Vector3f::Zero();
Vector3f ambient_ = geometry->ka() * geometry->ca(); Vector3f ambient_ =
geometry->ka() * geometry->ca().array() * Scene::current->ai().array();
Vector3f diffuse_ = geometry->kd() * geometry->cd().array() * id_.array() * Vector3f diffuse_ = geometry->kd() * geometry->cd().array() * id_.array() *
std::max(0.0f, hit.normal().dot(rayDirection)); std::max(0.0f, hit.normal().dot(rayDirection));

View file

@ -85,8 +85,10 @@ void RayTracer::output() {
void RayTracer::run() { void RayTracer::run() {
parse(); parse();
for (auto scene : scenes) for (auto scene : scenes) {
Scene::current = scene;
render(scene); render(scene);
}
output(); output();
} }

View file

@ -1,5 +1,7 @@
#include "Scene.h" #include "Scene.h"
Scene *Scene::current = nullptr;
string Scene::name() const { return name_; } string Scene::name() const { return name_; }
int Scene::width() { return width_; } int Scene::width() { return width_; }
@ -8,6 +10,8 @@ int Scene::height() { return height_; }
float Scene::fov() { return fov_; } float Scene::fov() { return fov_; }
Vector3f Scene::ai() const { return ai_; }
Vector3f Scene::center() const { return center_; } Vector3f Scene::center() const { return center_; }
Vector3f Scene::up() const { return up_; } Vector3f Scene::up() const { return up_; }

View file

@ -36,6 +36,7 @@ public:
int width(); int width();
int height(); int height();
float fov(); float fov();
Vector3f ai() const;
Vector3f center() const; Vector3f center() const;
Vector3f up() const; Vector3f up() const;
Vector3f lookAt() const; Vector3f lookAt() const;
@ -44,6 +45,7 @@ public:
void setAntialiasing(bool); void setAntialiasing(bool);
void setTwoSideRender(bool); void setTwoSideRender(bool);
void setGlobalIllum(bool); void setGlobalIllum(bool);
static Scene *current;
}; };
#endif // !SCENE_H_ #endif // !SCENE_H_