work on global illum

This commit is contained in:
Shuo Feng 2024-03-19 23:15:12 -04:00
parent 75faed07cc
commit 1c06958238
Signed by: sfeng
GPG key ID: 1E83AE6CD1C037B1
4 changed files with 31 additions and 3 deletions

View file

@ -40,6 +40,8 @@ Scene *Parser::getScene(const nlohmann::json &j) {
sc->setAntialiasing(j.value("antialiasing", false)); sc->setAntialiasing(j.value("antialiasing", false));
sc->setTwoSideRender(j.value("twosiderender", false)); sc->setTwoSideRender(j.value("twosiderender", false));
sc->setGlobalIllum(j.value("globalillum", false)); sc->setGlobalIllum(j.value("globalillum", false));
sc->setMaxBounce(j.value("maxbounce", 3));
sc->setProbTerminate(j.value("probTerminate", 0.33f));
if (j.contains("raysperpixel")) if (j.contains("raysperpixel"))
sc->setRaysPerPixel(getRpp(j["raysperpixel"])); sc->setRaysPerPixel(getRpp(j["raysperpixel"]));

View file

@ -17,7 +17,7 @@ using std::priority_queue;
Ray getRay(int, int); Ray getRay(int, int);
Ray getRay(int, int, int, int); Ray getRay(int, int, int, int);
void writeColor(int, const Vector3f &); void writeColor(int, const Vector3f &);
Vector3f trace(Ray r); utils::Optional<Vector3f> trace(Ray r);
Vector3f clamp(const Vector3f &); Vector3f clamp(const Vector3f &);
namespace camera { namespace camera {
@ -88,7 +88,11 @@ void RayTracer::render() {
for (int j = 0; j < gridHeight; ++j) for (int j = 0; j < gridHeight; ++j)
for (int i = 0; i < gridWidth; ++i) { for (int i = 0; i < gridWidth; ++i) {
Ray ray = getRay(x, y, i, j); 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) if (!success)
color = accumulate / success; color = accumulate / success;
@ -146,7 +150,13 @@ void writeColor(int i, const Vector3f &color) {
Output::current->b(i, color.z()); 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 { namespace camera {
int getGridWidth(VectorXi data) { int getGridWidth(VectorXi data) {

View file

@ -12,6 +12,10 @@ float Scene::fov() { return fov_; }
bool Scene::globalIllum() { return globalIllum_; } bool Scene::globalIllum() { return globalIllum_; }
int Scene::maxBounce() { return maxBounce_; }
float Scene::probTerminate() { return probTerminate_; }
Eigen::VectorXi Scene::raysPerPixel() const { return raysPerPixel_; } Eigen::VectorXi Scene::raysPerPixel() const { return raysPerPixel_; }
Vector3f Scene::ai() const { return ai_; } Vector3f Scene::ai() const { return ai_; }
@ -39,3 +43,9 @@ void Scene::setTwoSideRender(bool twoSideRender) {
void Scene::setGlobalIllum(bool globalIllum) { void Scene::setGlobalIllum(bool globalIllum) {
this->globalIllum_ = globalIllum; this->globalIllum_ = globalIllum;
} }
void Scene::setMaxBounce(int maxBounce) { this->maxBounce_ = maxBounce; }
void Scene::setProbTerminate(float probTerminate) {
this->probTerminate_ = probTerminate;
}

View file

@ -30,6 +30,8 @@ private:
bool antialiasing_ = false; bool antialiasing_ = false;
bool twoSideRender_ = false; bool twoSideRender_ = false;
bool globalIllum_ = false; bool globalIllum_ = false;
int maxBounce_ = 3;
float probTerminate_ = 0.33;
public: public:
static Scene *current; static Scene *current;
@ -39,6 +41,8 @@ public:
int height(); int height();
float fov(); float fov();
bool globalIllum(); bool globalIllum();
int maxBounce();
float probTerminate();
Vector3f ai() const; Vector3f ai() const;
Vector3f center() const; Vector3f center() const;
Vector3f up() const; Vector3f up() const;
@ -49,6 +53,8 @@ public:
void setAntialiasing(bool); void setAntialiasing(bool);
void setTwoSideRender(bool); void setTwoSideRender(bool);
void setGlobalIllum(bool); void setGlobalIllum(bool);
void setMaxBounce(int);
void setProbTerminate(float);
}; };
#endif // !SCENE_H_ #endif // !SCENE_H_