diff --git a/src/RayTracer.cc b/src/RayTracer.cc index 575585b..69c55b1 100644 --- a/src/RayTracer.cc +++ b/src/RayTracer.cc @@ -6,6 +6,7 @@ #include #include +#include #include using std::priority_queue; @@ -57,22 +58,36 @@ void RayTracer::render() { Output::current = new Output(Scene::current->backgroundColor(), Scene::current->name(), width, height); - for (int y = 0; y < height; ++y) - for (int x = 0; x < width; ++x) { - Ray ray = getRay(x, y, cameraPos, pxUpperLeft, du, dv); - priority_queue records; - for (auto g : geometries) { - Optional t = g->intersect(ray); - if (t.hasValue()) - records.push(HitRecord(t.value(), ray, g)); - } + int gridWidth = 1, gridHeight = 1, rpp = 1; + Eigen::VectorXi raysPerPixel = Scene::current->raysPerPixel(); - if (!records.empty()) { - HitRecord hit = records.top(); - hit.calcNormal(); - calculateColor(hit, y * width + x); - } - } + if (raysPerPixel.size() == 2) { + gridWidth = gridHeight = raysPerPixel.x(); + rpp = raysPerPixel.y(); + } else if (raysPerPixel.size() == 3) { + gridWidth = raysPerPixel.x(); + gridHeight = raysPerPixel.y(); + rpp = raysPerPixel.z(); + } + + for (int y = 0; y < height; ++y) + for (int x = 0; x < width; ++x) + for (int j = 0; j < gridHeight; ++j) + for (int i = 0; i < gridWidth; ++i) { + Ray ray = getRay(x, y, cameraPos, pxUpperLeft, du, dv); + priority_queue records; + for (auto g : geometries) { + Optional t = g->intersect(ray); + if (t.hasValue()) + records.push(HitRecord(t.value(), ray, g)); + } + + if (!records.empty()) { + HitRecord hit = records.top(); + hit.calcNormal(); + calculateColor(hit, y * width + x); + } + } } void RayTracer::run() { diff --git a/src/Scene.cc b/src/Scene.cc index f9d9840..b51ee11 100644 --- a/src/Scene.cc +++ b/src/Scene.cc @@ -10,6 +10,8 @@ int Scene::height() { return height_; } float Scene::fov() { return fov_; } +Eigen::VectorXi Scene::raysPerPixel() const { return raysPerPixel_; } + Vector3f Scene::ai() const { return ai_; } Vector3f Scene::center() const { return center_; } diff --git a/src/Scene.h b/src/Scene.h index 6775ac2..89eb9d2 100644 --- a/src/Scene.h +++ b/src/Scene.h @@ -41,6 +41,7 @@ public: Vector3f up() const; Vector3f lookAt() const; Vector3f backgroundColor() const; + Eigen::VectorXi raysPerPixel() const; void setRaysPerPixel(const Eigen::VectorXi &); void setAntialiasing(bool); void setTwoSideRender(bool);