From 1207c2c55c772155d02a148d76616881f3f6c125 Mon Sep 17 00:00:00 2001 From: Rosyid Haryadi Date: Sun, 2 Mar 2025 00:25:53 +0700 Subject: upd: anti aliasing --- src/global.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/global.rs') 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, } } -- cgit v1.2.3-70-g09d2