mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
set for global illum
This commit is contained in:
parent
0d450261a7
commit
f5936b2ada
3 changed files with 42 additions and 21 deletions
|
@ -40,6 +40,18 @@ void RayTracer::calculateColor(const HitRecord &hit, int i) {
|
||||||
Output::current->b(i, result.z());
|
Output::current->b(i, result.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getGridWidth(Eigen::VectorXi data) {
|
||||||
|
return data.size() != 2 && data.size() != 3 ? 1 : data.x();
|
||||||
|
}
|
||||||
|
|
||||||
|
int getGridHeight(Eigen::VectorXi data) {
|
||||||
|
return data.size() == 2 ? data.x() : (data.size() == 3 ? data.y() : 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getRayNumber(Eigen::VectorXi data) {
|
||||||
|
return data.size() == 2 ? data.y() : (data.size() == 3 ? data.z() : 1);
|
||||||
|
}
|
||||||
|
|
||||||
void RayTracer::render() {
|
void RayTracer::render() {
|
||||||
int width = Scene::current->width();
|
int width = Scene::current->width();
|
||||||
int height = Scene::current->height();
|
int height = Scene::current->height();
|
||||||
|
@ -59,23 +71,27 @@ 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);
|
||||||
|
|
||||||
int gridWidth = 1, gridHeight = 1, rpp = 1;
|
Eigen::VectorXi data = Scene::current->raysPerPixel();
|
||||||
Eigen::VectorXi raysPerPixel = Scene::current->raysPerPixel();
|
int gridWidth = getGridWidth(data);
|
||||||
|
int gridHeight = getGridHeight(data);
|
||||||
|
int raysPerPixel = getRayNumber(data);
|
||||||
|
|
||||||
if (raysPerPixel.size() == 2) {
|
Vector3f gdu = Vector3f::Zero();
|
||||||
gridWidth = gridHeight = raysPerPixel.x();
|
Vector3f gdv = Vector3f::Zero();
|
||||||
rpp = raysPerPixel.y();
|
if (gridWidth > 1 || gridHeight > 1) {
|
||||||
} else if (raysPerPixel.size() == 3) {
|
gdu = du / gridWidth;
|
||||||
gridWidth = raysPerPixel.x();
|
gdv = dv / gridHeight;
|
||||||
gridHeight = raysPerPixel.y();
|
|
||||||
rpp = raysPerPixel.z();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int y = 0; y < height; ++y) {
|
for (int y = 0; y < height; ++y) {
|
||||||
utils::Progress::of((y + 1.0f) / height);
|
utils::Progress::of((y + 1.0f) / height);
|
||||||
|
|
||||||
for (int x = 0; x < width; ++x)
|
for (int x = 0; x < width; ++x)
|
||||||
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) {
|
||||||
|
if (Scene::current->globalIllum()) {
|
||||||
|
// TODO: Path tracing for global illumination
|
||||||
|
} else {
|
||||||
Ray ray = getRay(x, y, cameraPos, pxUpperLeft, du, dv);
|
Ray ray = getRay(x, y, cameraPos, pxUpperLeft, du, dv);
|
||||||
priority_queue<HitRecord> records;
|
priority_queue<HitRecord> records;
|
||||||
for (auto g : geometries) {
|
for (auto g : geometries) {
|
||||||
|
@ -91,6 +107,7 @@ void RayTracer::render() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ int Scene::height() { return height_; }
|
||||||
|
|
||||||
float Scene::fov() { return fov_; }
|
float Scene::fov() { return fov_; }
|
||||||
|
|
||||||
|
bool Scene::globalIllum() { return globalIllum_; }
|
||||||
|
|
||||||
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_; }
|
||||||
|
|
|
@ -32,10 +32,13 @@ private:
|
||||||
bool globalIllum_ = false;
|
bool globalIllum_ = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static Scene *current;
|
||||||
|
|
||||||
string name() const;
|
string name() const;
|
||||||
int width();
|
int width();
|
||||||
int height();
|
int height();
|
||||||
float fov();
|
float fov();
|
||||||
|
bool globalIllum();
|
||||||
Vector3f ai() const;
|
Vector3f ai() const;
|
||||||
Vector3f center() const;
|
Vector3f center() const;
|
||||||
Vector3f up() const;
|
Vector3f up() const;
|
||||||
|
@ -46,7 +49,6 @@ public:
|
||||||
void setAntialiasing(bool);
|
void setAntialiasing(bool);
|
||||||
void setTwoSideRender(bool);
|
void setTwoSideRender(bool);
|
||||||
void setGlobalIllum(bool);
|
void setGlobalIllum(bool);
|
||||||
static Scene *current;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !SCENE_H_
|
#endif // !SCENE_H_
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue