diff options
author | Julian T <julian@jtle.dk> | 2021-01-14 00:56:57 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-01-14 00:56:57 +0100 |
commit | 57c2f9241543a7d18eab98077530730d49ee10c2 (patch) | |
tree | 9dcb819f6c89621f214346a3cbbc88762d05d831 /src/object.cpp | |
parent | 8251be3e7ec0e381391c951fd4c8f1ab8080bef9 (diff) |
Replace color with pbr-book inspired Spectrum class
Diffstat (limited to 'src/object.cpp')
-rw-r--r-- | src/object.cpp | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/object.cpp b/src/object.cpp index 0f7332f..40e21b2 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -4,13 +4,7 @@ #include <iostream> #include "core/common.hpp" -void Color::clamp() { - if (m_x > 1) { m_x = 1; } - if (m_y > 1) { m_y = 1; } - if (m_z > 1) { m_z = 1; } -} - -Material::Material(Color color, double defuse, double spectral, double spectral_pow, double emissive) { +Material::Material(Spectrum color, double defuse, double spectral, double spectral_pow, double emissive) { m_color = color; m_defuse = defuse; m_emissive = emissive; @@ -18,17 +12,17 @@ Material::Material(Color color, double defuse, double spectral, double spectral_ m_spectral_pow = spectral_pow; } -Color Material::reflect(const Vec3d &normal, const Vec3d &in, const Vec3d &out, const Color &incol) const { +Spectrum Material::reflect(const Vec3d &normal, const Vec3d &in, const Vec3d &out, const Spectrum &incol) const { // Emissive - Color c = Vec3d(m_color) * m_emissive; + Spectrum c = m_color * m_emissive; // Defuse - c += (Vec3d(m_color) * Vec3d(incol)) * (in.dot(normal) * m_defuse); + c += (m_color * incol) * (in.dot(normal) * m_defuse); // Spectral if (m_spectral > 0) { auto R = normal * (2 * normal.dot(in)) - in; - c += Vec3d(incol) * pow(out.dot(R) * m_spectral, m_spectral_pow); + c += incol * pow(out.dot(R) * m_spectral, m_spectral_pow); } return c; |