From de559b02d76d96387500cb804399acd94867b1ce Mon Sep 17 00:00:00 2001 From: JonOfUs Date: Sun, 17 Jul 2022 21:09:39 +0200 Subject: [PATCH] DIsable antialiasing if running with just one sample per pixel --- src/main.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8bea18f..efa4c5f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -264,13 +264,13 @@ fn main() { // Image let aspect_ratio = 16.0 / 9.0; - let image_width = 600; + let image_width = 1000; let image_height = (image_width as f64 / aspect_ratio) as u32; - let samples_per_pixel = 50_u32; + let samples_per_pixel = 1_u32; let max_depth = 50; let vfov = 50.0; - let lookfrom = Point3::new(30.0, 20.0, 30.0); + let lookfrom = Point3::new(-30.0, 20.0, -30.0); let lookat = Point3::new(0.0, 15.0, 0.0); let vup = Vec3::new(0.0, 1.0, 0.0); let dist_to_focus = 40.0; @@ -317,8 +317,15 @@ fn main() { let mut colors = Vec::new(); for i in 0..image_width { - let mut pixel_color = Color::new(0.0, 0.0, 0.0); - for _ in 0..samples_per_pixel { + let mut pixel_color = ray_color( + &cam.get_ray( + i as f64 / (image_width - 1) as f64, + j as f64 / (image_height - 1) as f64, + ), + &world, + max_depth, + ); // first ray not antialiased to disable antialiasing on value 1 + for _ in 1..samples_per_pixel { let u = (i as f64 + utility::random_f64()) / (image_width - 1) as f64; let v = (j as f64 + utility::random_f64()) / (image_height - 1) as f64; let r = cam.get_ray(u, v);