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());
|
||||
}
|
||||
|
||||
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() {
|
||||
int width = Scene::current->width();
|
||||
int height = Scene::current->height();
|
||||
|
@ -59,35 +71,40 @@ void RayTracer::render() {
|
|||
Output::current = new Output(Scene::current->backgroundColor(),
|
||||
Scene::current->name(), width, height);
|
||||
|
||||
int gridWidth = 1, gridHeight = 1, rpp = 1;
|
||||
Eigen::VectorXi raysPerPixel = Scene::current->raysPerPixel();
|
||||
Eigen::VectorXi data = Scene::current->raysPerPixel();
|
||||
int gridWidth = getGridWidth(data);
|
||||
int gridHeight = getGridHeight(data);
|
||||
int raysPerPixel = getRayNumber(data);
|
||||
|
||||
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();
|
||||
Vector3f gdu = Vector3f::Zero();
|
||||
Vector3f gdv = Vector3f::Zero();
|
||||
if (gridWidth > 1 || gridHeight > 1) {
|
||||
gdu = du / gridWidth;
|
||||
gdv = dv / gridHeight;
|
||||
}
|
||||
|
||||
for (int y = 0; y < height; ++y) {
|
||||
utils::Progress::of((y + 1.0f) / height);
|
||||
|
||||
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 (Scene::current->globalIllum()) {
|
||||
// TODO: Path tracing for global illumination
|
||||
} else {
|
||||
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);
|
||||
if (!records.empty()) {
|
||||
HitRecord hit = records.top();
|
||||
hit.calcNormal();
|
||||
calculateColor(hit, y * width + x);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ int Scene::height() { return height_; }
|
|||
|
||||
float Scene::fov() { return fov_; }
|
||||
|
||||
bool Scene::globalIllum() { return globalIllum_; }
|
||||
|
||||
Eigen::VectorXi Scene::raysPerPixel() const { return raysPerPixel_; }
|
||||
|
||||
Vector3f Scene::ai() const { return ai_; }
|
||||
|
|
|
@ -32,10 +32,13 @@ private:
|
|||
bool globalIllum_ = false;
|
||||
|
||||
public:
|
||||
static Scene *current;
|
||||
|
||||
string name() const;
|
||||
int width();
|
||||
int height();
|
||||
float fov();
|
||||
bool globalIllum();
|
||||
Vector3f ai() const;
|
||||
Vector3f center() const;
|
||||
Vector3f up() const;
|
||||
|
@ -46,7 +49,6 @@ public:
|
|||
void setAntialiasing(bool);
|
||||
void setTwoSideRender(bool);
|
||||
void setGlobalIllum(bool);
|
||||
static Scene *current;
|
||||
};
|
||||
|
||||
#endif // !SCENE_H_
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue