aboutsummaryrefslogtreecommitdiff
path: root/src/core/spectrum.cpp
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-01-14 00:56:57 +0100
committerJulian T <julian@jtle.dk>2021-01-14 00:56:57 +0100
commit57c2f9241543a7d18eab98077530730d49ee10c2 (patch)
tree9dcb819f6c89621f214346a3cbbc88762d05d831 /src/core/spectrum.cpp
parent8251be3e7ec0e381391c951fd4c8f1ab8080bef9 (diff)
Replace color with pbr-book inspired Spectrum class
Diffstat (limited to 'src/core/spectrum.cpp')
-rw-r--r--src/core/spectrum.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/core/spectrum.cpp b/src/core/spectrum.cpp
new file mode 100644
index 0000000..d53cf49
--- /dev/null
+++ b/src/core/spectrum.cpp
@@ -0,0 +1,90 @@
+#include "spectrum.hpp"
+
+static double clamp(double v, double low = 0, double high = 0) {
+ if (v < low) {
+ return low;
+ }
+ if (v > high) {
+ return high;
+ }
+ return v;
+}
+
+Spectrum::Spectrum(double v) {
+ c[0] = v;
+ c[1] = v;
+ c[2] = v;
+}
+
+Spectrum Spectrum::FromRGB(double r, double g, double b) {
+ Spectrum ret;
+ ret.c[0] = r;
+ ret.c[1] = g;
+ ret.c[2] = b;
+
+ return ret;
+}
+
+Spectrum &Spectrum::operator+=(const Spectrum &o) {
+ c[0] += o.c[0];
+ c[1] += o.c[1];
+ c[2] += o.c[2];
+
+ return *this;
+}
+
+Spectrum &Spectrum::operator*=(double o) {
+ c[0] *= o;
+ c[1] *= o;
+ c[2] *= o;
+
+ return *this;
+}
+
+Spectrum Spectrum::operator+(const Spectrum &o) const {
+ Spectrum ret = *this;
+
+ ret.c[0] += o.c[0];
+ ret.c[1] += o.c[1];
+ ret.c[2] += o.c[2];
+
+ return ret;
+}
+
+Spectrum Spectrum::operator-(const Spectrum &o) const {
+ Spectrum ret = *this;
+
+ ret.c[0] -= o.c[0];
+ ret.c[1] -= o.c[1];
+ ret.c[2] -= o.c[2];
+
+ return ret;
+}
+
+Spectrum Spectrum::operator*(const Spectrum &o) const {
+ Spectrum ret = *this;
+
+ ret.c[0] *= o.c[0];
+ ret.c[1] *= o.c[1];
+ ret.c[2] *= o.c[2];
+
+ return ret;
+}
+
+Spectrum Spectrum::operator/(const Spectrum &o) const {
+ Spectrum ret = *this;
+
+ ret.c[0] /= o.c[0];
+ ret.c[1] /= o.c[1];
+ ret.c[2] /= o.c[2];
+
+ return ret;
+}
+
+Spectrum Spectrum::clamp(double low, double high) const {
+ Spectrum ret;
+ ret.c[0] = ::clamp(c[0], low, high);
+ ret.c[1] = ::clamp(c[1], low, high);
+ ret.c[2] = ::clamp(c[2], low, high);
+ return ret;
+}