diff options
author | Julian T <julian@jtle.dk> | 2021-02-06 23:43:06 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-02-06 23:43:06 +0100 |
commit | b64c7e972c52b7d015d661866f0cf902370343e5 (patch) | |
tree | 8d3dc9a8ae6b491b9f8f639f2d0bad6387d59069 /src/core/spectrum.rs | |
parent | 0d5e6bd9363d5ed5c4f28174819fc0f5fd9aa586 (diff) |
Implement pathtracing
Diffstat (limited to 'src/core/spectrum.rs')
-rw-r--r-- | src/core/spectrum.rs | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/core/spectrum.rs b/src/core/spectrum.rs index 41b3342..727a1b6 100644 --- a/src/core/spectrum.rs +++ b/src/core/spectrum.rs @@ -6,7 +6,7 @@ use std::ops; // TODO implement SampledSpectrum instead for nicer images -#[derive(Clone, Default)] +#[derive(Clone, Copy, Default)] pub struct Spectrum { c: [Float; 3], } @@ -19,9 +19,17 @@ impl Spectrum { pub fn to_rgb(&self, scale: Float) -> (Float, Float, Float) { (self.c[0] * scale, self.c[1] * scale, self.c[2] * scale) } + + pub fn gamma_correct(&self) -> Self { + Self::new_rgb( + self.c[0].sqrt(), + self.c[1].sqrt(), + self.c[2].sqrt(), + ) + } } -impl std::ops::Mul<Float> for &Spectrum { +impl std::ops::Mul<Float> for Spectrum { type Output = Spectrum; fn mul(self, op: Float) -> Self::Output { @@ -33,7 +41,7 @@ impl std::ops::Mul<Float> for &Spectrum { } } -impl std::ops::Div<Float> for &Spectrum { +impl std::ops::Div<Float> for Spectrum { type Output = Spectrum; fn div(self, op: Float) -> Self::Output { @@ -45,6 +53,18 @@ impl std::ops::Div<Float> for &Spectrum { } } +impl std::ops::Add for Spectrum { + type Output = Spectrum; + + fn add(self, op: Self) -> Self::Output { + Self::Output::new_rgb( + self.c[0] + op.c[0], + self.c[1] + op.c[1], + self.c[2] + op.c[2], + ) + } +} + impl std::ops::AddAssign<&Self> for Spectrum { fn add_assign(&mut self, op: &Self) { self.c[0] += op.c[0]; |