write background color

This commit is contained in:
Shuo Feng 2024-02-22 19:49:26 -05:00
parent d808e05449
commit 812317f2ee
Signed by: sfeng
GPG key ID: 1E83AE6CD1C037B1
3 changed files with 10 additions and 0 deletions

View file

@ -40,6 +40,13 @@ void RayTracer::render(Scene *scene) {
Vector3f pxUpperLeft = vpUpperLeft + (du + dv) / 2.0;
Buffer buffer(width * height * 3);
Vector3f bgc = scene->getBackgroundColor();
for (int i = 0; i < width * height; ++i) {
buffer[i * 3] = bgc.x();
buffer[i * 3 + 1] = bgc.y();
buffer[i * 3 + 2] = bgc.z();
}
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x) {
Ray ray = getRay(x, y, cameraPos, pxUpperLeft, du, dv);

View file

@ -14,6 +14,8 @@ Vector3f Scene::getUpVector() const { return up; }
Vector3f Scene::getLookAt() const { return lookAt; }
Vector3f Scene::getBackgroundColor() const { return backgroundColor; }
void Scene::setRaysPerPixel(const Eigen::VectorXi &raysPerPixel) {
this->raysPerPixel = raysPerPixel;
}

View file

@ -39,6 +39,7 @@ public:
Vector3f getCenter() const;
Vector3f getUpVector() const;
Vector3f getLookAt() const;
Vector3f getBackgroundColor() const;
void setRaysPerPixel(const Eigen::VectorXi &);
void setAntialiasing(bool);
void setTwoSideRender(bool);