mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +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>
|
||||
|
||||
Vector3f Geometry::diffuse() const { return cd; }
|
||||
Vector3f Geometry::specular() const { return cs; }
|
||||
Vector3f Geometry::ambient() const { return ca; }
|
||||
|
||||
void Geometry::setTransform(const Matrix4f &transform) {
|
||||
this->transform = transform;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,9 @@ protected:
|
|||
Matrix4f transform = Matrix4f::Identity();
|
||||
|
||||
public:
|
||||
Vector3f diffuse() const;
|
||||
Vector3f specular() const;
|
||||
Vector3f ambient() const;
|
||||
void setTransform(const Matrix4f &);
|
||||
};
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ void Output::write() {
|
|||
for (unsigned int x = 0; x < width; ++x)
|
||||
fout << (char)(255.0f * red[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();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,10 @@ using std::vector;
|
|||
class Output {
|
||||
public:
|
||||
Output(const Vector3f &bgc, string path, int w, int h)
|
||||
: red(vector<float>(w * h, bgc.x())),
|
||||
green(vector<float>(w * h, bgc.y())),
|
||||
blue(vector<float>(w * h, bgc.z())), path(path), width(w), height(h) {}
|
||||
: red(vector<float>(w * h + 1, bgc.x())),
|
||||
green(vector<float>(w * h + 1, bgc.y())),
|
||||
blue(vector<float>(w * h + 1, bgc.z())), path(path), width(w),
|
||||
height(h) {}
|
||||
|
||||
void write();
|
||||
|
||||
|
|
|
@ -47,14 +47,16 @@ void RayTracer::render(Scene *scene) {
|
|||
for (int x = 0; x < width; ++x) {
|
||||
Ray ray = getRay(x, y, cameraPos, pxUpperLeft, du, dv);
|
||||
|
||||
for (auto geometry : geometries)
|
||||
if (geometry->intersect(ray)) {
|
||||
buffer->r(y * width + x, 1);
|
||||
buffer->g(y * width + x, 1);
|
||||
buffer->b(y * width + x, 1);
|
||||
for (auto g : geometries)
|
||||
if (g->intersect(ray)) {
|
||||
Vector3f diffuse = g->diffuse();
|
||||
buffer->r(y * width + x, diffuse.x());
|
||||
buffer->g(y * width + x, diffuse.y());
|
||||
buffer->b(y * width + x, diffuse.z());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
outputs.push_back(buffer);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue