diff options
Diffstat (limited to 'src/common.rs')
-rw-r--r-- | src/common.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/common.rs b/src/common.rs index 3975609..a676939 100644 --- a/src/common.rs +++ b/src/common.rs @@ -11,12 +11,14 @@ pub const FOCAL_LENGTH: f32 = 1.0; pub const CAMERA_CENTER: Point3 = Point3 { x: 0f32, y: 0f32, z: 0f32 }; pub const SAMPLES_PER_PIXEL: usize = 100; +pub const MAX_DEPTH: usize = 50; pub const fn get_image_height(image_width: usize, aspect_ratio: f32) -> usize { let image_height = (image_width as f32 / aspect_ratio) as usize; if image_width < 1 { 1 } else { image_height } } +#[derive(Debug, Clone)] pub struct Color { pub r: f32, pub g: f32, @@ -43,6 +45,16 @@ impl Color { b: self.b + other.b } } + + fn _linear_to_gamma(linear_comp: f32) -> f32 { + if linear_comp > 0.0 { linear_comp.sqrt() } else { 0.0 } + } + + pub fn linear_to_gamma(&mut self) { + self.r = Self::_linear_to_gamma(self.r); + self.g = Self::_linear_to_gamma(self.g); + self.b = Self::_linear_to_gamma(self.b); + } } @@ -64,6 +76,8 @@ impl Pixel { } pub fn from_color(color: &Color) -> Self { + let mut clone = color.clone(); + clone.linear_to_gamma(); let (r, g, b) = (color.r, color.g, color.b); Self::from_frac(r, g, b) } |