mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
add ambient intensity
This commit is contained in:
parent
ef5df2fa64
commit
641b62ca01
4 changed files with 13 additions and 2 deletions
|
@ -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));
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_; }
|
||||||
|
|
|
@ -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_
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue