diff options
author | Julian T <julian@jtle.dk> | 2020-08-11 21:21:02 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2020-08-11 21:21:02 +0200 |
commit | 690b72664ca8d471f5c117f6ed87aeae2de0a208 (patch) | |
tree | 8bc30efc009462d4390ac6eb8fe28ccbdbbd88a1 /src/object.hpp | |
parent | 3b8893902ac5f529faf15accaa3fb5360771d3b3 (diff) |
Defuse coloring
Diffstat (limited to 'src/object.hpp')
-rw-r--r-- | src/object.hpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/object.hpp b/src/object.hpp index ac5122f..2957acb 100644 --- a/src/object.hpp +++ b/src/object.hpp @@ -5,20 +5,44 @@ #include "vector.hpp" #include "ray.hpp" +class Color : public Vec3d { + public: + Color() {} + Color(const Vec3d &v) : Vec3d(v) {} + Color(double r, double g, double b) : Vec3d(r, g, b) {} + + uint8_t r() { return m_x * 255; } + uint8_t g() { return m_y * 255; } + uint8_t b() { return m_z * 255; } + + void clamp(); + +}; + +// Implements phong BRDF class Material { + public: + Material(Color color, double defuse); + + Color reflect(const Vec3d &normal, const Vec3d &in, const Vec3d &out) const; + private: + Color m_color; + double m_defuse; }; class Shape { public: - void setMaterial(std::shared_ptr<Material> m); + Shape(const Material &mat) : m_mat(mat) { } virtual Vec3d norm_at(const Vec3d &point, const Vec3d &indir) const = 0; virtual double intersect(const Ray &ray, bool skip_dist) const = 0; + + const Material &m_mat; }; class Sphere : public Shape { public: - Sphere(Vec3d center, double radius); + Sphere(const Material &mat, Vec3d center, double radius); Vec3d norm_at(const Vec3d &point, const Vec3d &indir) const; double intersect(const Ray &ray, bool skip_dist) const; @@ -29,7 +53,7 @@ class Sphere : public Shape { class Plane : public Shape { public: - Plane(Vec3d start, Vec3d norm); + Plane(const Material &mat, Vec3d start, Vec3d norm); Vec3d norm_at(const Vec3d &point, const Vec3d &indir) const; double intersect(const Ray &ray, bool skip_dist) const; |