add rays per pixel

This commit is contained in:
Shuo Feng 2024-03-18 00:15:21 -04:00
parent 2efe817cd7
commit 4d4c257ef1
Signed by: sfeng
GPG key ID: 1E83AE6CD1C037B1
3 changed files with 33 additions and 15 deletions

View file

@ -6,6 +6,7 @@
#include <Eigen/Core>
#include <cmath>
#include <iostream>
#include <queue>
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<HitRecord> records;
for (auto g : geometries) {
Optional<float> 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<HitRecord> records;
for (auto g : geometries) {
Optional<float> 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() {

View file

@ -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_; }

View file

@ -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);