mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +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 <Eigen/Core>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <iostream>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
using std::priority_queue;
|
using std::priority_queue;
|
||||||
|
@ -57,22 +58,36 @@ void RayTracer::render() {
|
||||||
Output::current = new Output(Scene::current->backgroundColor(),
|
Output::current = new Output(Scene::current->backgroundColor(),
|
||||||
Scene::current->name(), width, height);
|
Scene::current->name(), width, height);
|
||||||
|
|
||||||
for (int y = 0; y < height; ++y)
|
int gridWidth = 1, gridHeight = 1, rpp = 1;
|
||||||
for (int x = 0; x < width; ++x) {
|
Eigen::VectorXi raysPerPixel = Scene::current->raysPerPixel();
|
||||||
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()) {
|
if (raysPerPixel.size() == 2) {
|
||||||
HitRecord hit = records.top();
|
gridWidth = gridHeight = raysPerPixel.x();
|
||||||
hit.calcNormal();
|
rpp = raysPerPixel.y();
|
||||||
calculateColor(hit, y * width + x);
|
} 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() {
|
void RayTracer::run() {
|
||||||
|
|
|
@ -10,6 +10,8 @@ int Scene::height() { return height_; }
|
||||||
|
|
||||||
float Scene::fov() { return fov_; }
|
float Scene::fov() { return fov_; }
|
||||||
|
|
||||||
|
Eigen::VectorXi Scene::raysPerPixel() const { return raysPerPixel_; }
|
||||||
|
|
||||||
Vector3f Scene::ai() const { return ai_; }
|
Vector3f Scene::ai() const { return ai_; }
|
||||||
|
|
||||||
Vector3f Scene::center() const { return center_; }
|
Vector3f Scene::center() const { return center_; }
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
Vector3f up() const;
|
Vector3f up() const;
|
||||||
Vector3f lookAt() const;
|
Vector3f lookAt() const;
|
||||||
Vector3f backgroundColor() const;
|
Vector3f backgroundColor() const;
|
||||||
|
Eigen::VectorXi raysPerPixel() const;
|
||||||
void setRaysPerPixel(const Eigen::VectorXi &);
|
void setRaysPerPixel(const Eigen::VectorXi &);
|
||||||
void setAntialiasing(bool);
|
void setAntialiasing(bool);
|
||||||
void setTwoSideRender(bool);
|
void setTwoSideRender(bool);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue