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::{ use crate::primitives::{
Vec2i, Vec2i,
Vec3, Vec3,
Rect,
}; };
use crate::scene::{ use crate::scene::{
Camera, Camera,
@@ -56,15 +55,25 @@ fn main() {
// The render loop should now be a job submission mechanism // The render loop should now be a job submission mechanism
// Iterate lines, submitting them as tasks to the thread. // Iterate lines, submitting them as tasks to the thread.
println!("P3\n{} {}\n255", image.x, image.y); println!("P3\n{} {}\n255", image.x, image.y);
let tile = Tile::render_tile( // TILE BASED RENDERER
Rect { x: 0, y: 0, w: image.x, h: image.y }, // let tile = Tile::render_tile(
image, // Rect { x: 0, y: 0, w: image.x, h: image.y },
&scene, // image,
&render_config, // &scene,
&mut small_rng // &render_config,
); // &mut small_rng
for pixel in tile.pixels.iter().rev() { // );
println!("{}", pixel.print_ppm(render_config.samples)); // 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!"); eprintln!("Done!");
} }

View File

@@ -121,23 +121,18 @@ impl Tile {
} }
} }
pub fn render_line( pub fn render_line(
bounds: Rect, y: i32, // bounding rect and line y: i32, // bounding rect and line
img_size: Vec2i, img_size: Vec2i,
scene: &Scene, scene: &Scene,
properties: &RenderProperties, properties: &RenderProperties,
rng: &mut SmallRng, // rng utils rng: &mut SmallRng, // rng utils
) -> Self { ) -> Self {
let pixels = (0..bounds.w) Tile::render_tile(
.map ( |x| -> Vec3{ Rect{ x: 0, y, w: img_size.x, h: 1 },
sample_pixel( img_size,
Vec2i{x, y}, scene,
scene, properties,
properties, rng
img_size, )
rng,
)
})
.collect();
Self { _bounds: bounds, pixels }
} }
} }