diff options
author | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2025-03-02 00:25:53 +0700 |
---|---|---|
committer | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2025-03-02 00:25:53 +0700 |
commit | 1207c2c55c772155d02a148d76616881f3f6c125 (patch) | |
tree | 9a504e189f88f0417adcc558c268b408701cad58 /src/global.rs | |
parent | 5fb34460b02b2b151dd775e43675bd4f09d2633a (diff) |
upd: anti aliasing
Diffstat (limited to 'src/global.rs')
-rw-r--r-- | src/global.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/global.rs b/src/global.rs index fc9e0c9..3f74ba1 100644 --- a/src/global.rs +++ b/src/global.rs @@ -1,4 +1,5 @@ use crate::calculus::calculus::Point3; +use crate::interval::Interval; // "Ideal" aspect ratio, allowing fraction pub const ASPECT_RATIO: f32 = 16.0f32 / 9.0f32; @@ -9,6 +10,8 @@ pub const VIEWPORT_HEIGHT: f32 = 2.0; 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 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 } @@ -52,10 +55,11 @@ pub struct Pixel { impl Pixel { pub fn from_frac(r: f32, g: f32, b: f32) -> Self { + let intensity = Interval::new(0.0, 0.999); Self { - r: (255.999 * r) as u8, - g: (255.999 * g) as u8, - b: (255.999 * b) as u8, + r: (256.0 * intensity.clamp(r)) as u8, + g: (256.0 * intensity.clamp(g)) as u8, + b: (256.0 * intensity.clamp(b)) as u8, } } |