aboutsummaryrefslogtreecommitdiff
path: root/src/object.cpp
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-09-16 20:52:12 +0200
committerJulian T <julian@jtle.dk>2020-12-06 22:44:10 +0100
commit0f9e88ccf0510ab4d830529fa539ef6db715f988 (patch)
tree863b5f466d3e81e16e04aad56ef7a0d860a143f9 /src/object.cpp
parenta38e6014ea5441e9d29fcb3b5607cd94e4061cff (diff)
Added first draft of spectral lightningold_spectral
Diffstat (limited to 'src/object.cpp')
-rw-r--r--src/object.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/object.cpp b/src/object.cpp
index 1449cbb..15fc267 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -10,15 +10,28 @@ void Color::clamp() {
if (m_z > 1) { m_z = 1; }
}
-Material::Material(Color color, double defuse, double emissive) {
+Material::Material(Color color, double defuse, double spectral, double spectral_pow, double emissive) {
m_color = color;
m_defuse = defuse;
m_emissive = emissive;
+ m_spectral = spectral;
+ m_spectral_pow = spectral_pow;
}
Color Material::reflect(const Vec3d &normal, const Vec3d &in, const Vec3d &out, const Color &incol) const {
- return Vec3d(m_color) * m_emissive +
- (Vec3d(m_color) * Vec3d(incol)) * (out.dot(normal) * m_defuse);
+ // Emissive
+ Color c = Vec3d(m_color) * m_emissive;
+
+ // Defuse
+ c += (Vec3d(m_color) * Vec3d(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);
+ }
+
+ return c;
}
Sphere::Sphere(const Material &mat, Vec3d center, double radius) : Shape(mat) {