mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-07 23:12:00 +00:00
add rays per pixel
This commit is contained in:
parent
2efe817cd7
commit
4d4c257ef1
3 changed files with 33 additions and 15 deletions
|
@ -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() {
|
||||
|
|
|
@ -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_; }
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue