mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
work on global illum
This commit is contained in:
parent
75faed07cc
commit
1c06958238
4 changed files with 31 additions and 3 deletions
|
@ -40,6 +40,8 @@ Scene *Parser::getScene(const nlohmann::json &j) {
|
|||
sc->setAntialiasing(j.value("antialiasing", false));
|
||||
sc->setTwoSideRender(j.value("twosiderender", false));
|
||||
sc->setGlobalIllum(j.value("globalillum", false));
|
||||
sc->setMaxBounce(j.value("maxbounce", 3));
|
||||
sc->setProbTerminate(j.value("probTerminate", 0.33f));
|
||||
if (j.contains("raysperpixel"))
|
||||
sc->setRaysPerPixel(getRpp(j["raysperpixel"]));
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ using std::priority_queue;
|
|||
Ray getRay(int, int);
|
||||
Ray getRay(int, int, int, int);
|
||||
void writeColor(int, const Vector3f &);
|
||||
Vector3f trace(Ray r);
|
||||
utils::Optional<Vector3f> trace(Ray r);
|
||||
Vector3f clamp(const Vector3f &);
|
||||
|
||||
namespace camera {
|
||||
|
@ -88,7 +88,11 @@ void RayTracer::render() {
|
|||
for (int j = 0; j < gridHeight; ++j)
|
||||
for (int i = 0; i < gridWidth; ++i) {
|
||||
Ray ray = getRay(x, y, i, j);
|
||||
accumulate += trace(ray);
|
||||
utils::Optional<Vector3f> result = trace(ray);
|
||||
if (result.hasValue()) {
|
||||
accumulate += result.value() * raysPerPixel;
|
||||
success += raysPerPixel;
|
||||
}
|
||||
}
|
||||
if (!success)
|
||||
color = accumulate / success;
|
||||
|
@ -146,7 +150,13 @@ void writeColor(int i, const Vector3f &color) {
|
|||
Output::current->b(i, color.z());
|
||||
}
|
||||
|
||||
Vector3f trace(Ray r) { return Vector3f::Zero(); }
|
||||
Vector3f trace(Ray r, int bounce, float prob) {}
|
||||
|
||||
utils::Optional<Vector3f> trace(Ray r) {
|
||||
Vector3f color =
|
||||
trace(r, Scene::current->maxBounce(), Scene::current->probTerminate());
|
||||
return utils::Optional<Vector3f>::nullopt;
|
||||
}
|
||||
|
||||
namespace camera {
|
||||
int getGridWidth(VectorXi data) {
|
||||
|
|
10
src/Scene.cc
10
src/Scene.cc
|
@ -12,6 +12,10 @@ float Scene::fov() { return fov_; }
|
|||
|
||||
bool Scene::globalIllum() { return globalIllum_; }
|
||||
|
||||
int Scene::maxBounce() { return maxBounce_; }
|
||||
|
||||
float Scene::probTerminate() { return probTerminate_; }
|
||||
|
||||
Eigen::VectorXi Scene::raysPerPixel() const { return raysPerPixel_; }
|
||||
|
||||
Vector3f Scene::ai() const { return ai_; }
|
||||
|
@ -39,3 +43,9 @@ void Scene::setTwoSideRender(bool twoSideRender) {
|
|||
void Scene::setGlobalIllum(bool globalIllum) {
|
||||
this->globalIllum_ = globalIllum;
|
||||
}
|
||||
|
||||
void Scene::setMaxBounce(int maxBounce) { this->maxBounce_ = maxBounce; }
|
||||
|
||||
void Scene::setProbTerminate(float probTerminate) {
|
||||
this->probTerminate_ = probTerminate;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ private:
|
|||
bool antialiasing_ = false;
|
||||
bool twoSideRender_ = false;
|
||||
bool globalIllum_ = false;
|
||||
int maxBounce_ = 3;
|
||||
float probTerminate_ = 0.33;
|
||||
|
||||
public:
|
||||
static Scene *current;
|
||||
|
@ -39,6 +41,8 @@ public:
|
|||
int height();
|
||||
float fov();
|
||||
bool globalIllum();
|
||||
int maxBounce();
|
||||
float probTerminate();
|
||||
Vector3f ai() const;
|
||||
Vector3f center() const;
|
||||
Vector3f up() const;
|
||||
|
@ -49,6 +53,8 @@ public:
|
|||
void setAntialiasing(bool);
|
||||
void setTwoSideRender(bool);
|
||||
void setGlobalIllum(bool);
|
||||
void setMaxBounce(int);
|
||||
void setProbTerminate(float);
|
||||
};
|
||||
|
||||
#endif // !SCENE_H_
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue