mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 15:31:59 +00:00
bugfix: color shadow
This commit is contained in:
parent
43a8204032
commit
a8a00d386e
5 changed files with 19 additions and 9 deletions
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
#include <Eigen/Dense>
|
#include <Eigen/Dense>
|
||||||
|
|
||||||
|
Vector3f Geometry::diffuse() const { return cd; }
|
||||||
|
Vector3f Geometry::specular() const { return cs; }
|
||||||
|
Vector3f Geometry::ambient() const { return ca; }
|
||||||
|
|
||||||
void Geometry::setTransform(const Matrix4f &transform) {
|
void Geometry::setTransform(const Matrix4f &transform) {
|
||||||
this->transform = transform;
|
this->transform = transform;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,9 @@ protected:
|
||||||
Matrix4f transform = Matrix4f::Identity();
|
Matrix4f transform = Matrix4f::Identity();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Vector3f diffuse() const;
|
||||||
|
Vector3f specular() const;
|
||||||
|
Vector3f ambient() const;
|
||||||
void setTransform(const Matrix4f &);
|
void setTransform(const Matrix4f &);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ void Output::write() {
|
||||||
for (unsigned int x = 0; x < width; ++x)
|
for (unsigned int x = 0; x < width; ++x)
|
||||||
fout << (char)(255.0f * red[y * width + x])
|
fout << (char)(255.0f * red[y * width + x])
|
||||||
<< (char)(255.0f * green[y * width + x])
|
<< (char)(255.0f * green[y * width + x])
|
||||||
<< (char)(255.0f * blue[y * height + x]);
|
<< (char)(255.0f * blue[y * width + x]);
|
||||||
fout.close();
|
fout.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,10 @@ using std::vector;
|
||||||
class Output {
|
class Output {
|
||||||
public:
|
public:
|
||||||
Output(const Vector3f &bgc, string path, int w, int h)
|
Output(const Vector3f &bgc, string path, int w, int h)
|
||||||
: red(vector<float>(w * h, bgc.x())),
|
: red(vector<float>(w * h + 1, bgc.x())),
|
||||||
green(vector<float>(w * h, bgc.y())),
|
green(vector<float>(w * h + 1, bgc.y())),
|
||||||
blue(vector<float>(w * h, bgc.z())), path(path), width(w), height(h) {}
|
blue(vector<float>(w * h + 1, bgc.z())), path(path), width(w),
|
||||||
|
height(h) {}
|
||||||
|
|
||||||
void write();
|
void write();
|
||||||
|
|
||||||
|
|
|
@ -47,14 +47,16 @@ void RayTracer::render(Scene *scene) {
|
||||||
for (int x = 0; x < width; ++x) {
|
for (int x = 0; x < width; ++x) {
|
||||||
Ray ray = getRay(x, y, cameraPos, pxUpperLeft, du, dv);
|
Ray ray = getRay(x, y, cameraPos, pxUpperLeft, du, dv);
|
||||||
|
|
||||||
for (auto geometry : geometries)
|
for (auto g : geometries)
|
||||||
if (geometry->intersect(ray)) {
|
if (g->intersect(ray)) {
|
||||||
buffer->r(y * width + x, 1);
|
Vector3f diffuse = g->diffuse();
|
||||||
buffer->g(y * width + x, 1);
|
buffer->r(y * width + x, diffuse.x());
|
||||||
buffer->b(y * width + x, 1);
|
buffer->g(y * width + x, diffuse.y());
|
||||||
|
buffer->b(y * width + x, diffuse.z());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outputs.push_back(buffer);
|
outputs.push_back(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue