From a701b9407ba0d1f9e2542ab01da385fbaf837895 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Mon, 25 Sep 2023 11:25:17 -0700 Subject: [PATCH] Line renderer in terms of tile renderer Done and done. --- src/main.rs | 29 +++++++++++++++++++---------- src/renderer.rs | 21 ++++++++------------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0b76ac0..236851d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,6 @@ mod renderer; use crate::primitives::{ Vec2i, Vec3, - Rect, }; use crate::scene::{ Camera, @@ -56,15 +55,25 @@ fn main() { // The render loop should now be a job submission mechanism // Iterate lines, submitting them as tasks to the thread. println!("P3\n{} {}\n255", image.x, image.y); - let tile = Tile::render_tile( - Rect { x: 0, y: 0, w: image.x, h: image.y }, - image, - &scene, - &render_config, - &mut small_rng - ); - for pixel in tile.pixels.iter().rev() { - println!("{}", pixel.print_ppm(render_config.samples)); + // TILE BASED RENDERER + // let tile = Tile::render_tile( + // Rect { x: 0, y: 0, w: image.x, h: image.y }, + // image, + // &scene, + // &render_config, + // &mut small_rng + // ); + // for pixel in tile.pixels.iter().rev() { + // println!("{}", pixel.print_ppm(render_config.samples)); + // } + + // LINE BASED RENDERER + for row in (0..image.y).rev() { + let tile = Tile::render_line(row, image, &scene, &render_config, &mut small_rng); + eprintln!("Printing scanline #{}", row); + for pixel in tile.pixels { + println!("{}", pixel.print_ppm(render_config.samples)) + } } eprintln!("Done!"); } diff --git a/src/renderer.rs b/src/renderer.rs index dac9033..c1bdbb5 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -121,23 +121,18 @@ impl Tile { } } pub fn render_line( - bounds: Rect, y: i32, // bounding rect and line + y: i32, // bounding rect and line img_size: Vec2i, scene: &Scene, properties: &RenderProperties, rng: &mut SmallRng, // rng utils ) -> Self { - let pixels = (0..bounds.w) - .map ( |x| -> Vec3{ - sample_pixel( - Vec2i{x, y}, - scene, - properties, - img_size, - rng, - ) - }) - .collect(); - Self { _bounds: bounds, pixels } + Tile::render_tile( + Rect{ x: 0, y, w: img_size.x, h: 1 }, + img_size, + scene, + properties, + rng + ) } }