Line renderer in terms of tile renderer
Done and done.
This commit is contained in:
29
src/main.rs
29
src/main.rs
@@ -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!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user