Line renderer in terms of tile renderer

Done and done.
This commit is contained in:
2023-09-25 11:25:17 -07:00
parent 72f154510f
commit a701b9407b
2 changed files with 27 additions and 23 deletions

View File

@@ -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!");
}

View File

@@ -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
)
}
}