Proper tile rendering
The Tile can now render a region of height > 1px! I'm gonna rewrite the render_line() function to operate in terms of the render_tile() function. A line is, after all, just a tile of height 1px.
This commit is contained in:
22
src/main.rs
22
src/main.rs
@@ -56,19 +56,15 @@ 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);
|
||||
for row in (0..image.y).rev() {
|
||||
let bounds = Rect{ // render boundary (a horizontal slice)
|
||||
x: 0,
|
||||
y: row,
|
||||
w: image.x,
|
||||
h: 1
|
||||
};
|
||||
let tile = Tile::render_line(bounds, row, image, &scene, &render_config, &mut small_rng);
|
||||
eprintln!("Printing scanline #{}", row);
|
||||
for pixel in tile.pixels {
|
||||
println!("{}", pixel.print_ppm(render_config.samples))
|
||||
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));
|
||||
}
|
||||
}
|
||||
// TODO: Dispatcher shutdown mechanism. Right now, we might technically be leaking threads.
|
||||
eprintln!("Done!");
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ use crate::scene::{
|
||||
|
||||
use rand::rngs::SmallRng;
|
||||
|
||||
use itertools::{self, Itertools};
|
||||
|
||||
const SKY_COLOR: Vec3 = Vec3 { x: 0.5, y: 0.7, z: 1.0};
|
||||
|
||||
pub struct RenderProperties {
|
||||
@@ -93,6 +95,31 @@ pub struct Tile {
|
||||
}
|
||||
|
||||
impl Tile {
|
||||
pub fn render_tile(
|
||||
bounds: Rect, // bounds of the region to render
|
||||
img_size: Vec2i, // final image resolution (needed for proper UV mapping)
|
||||
scene: &Scene,
|
||||
properties: &RenderProperties, // TODO: Place image size in render properties?
|
||||
rng: &mut SmallRng,
|
||||
) -> Self {
|
||||
let pixel_iter = (bounds.y..(bounds.y + bounds.h))
|
||||
.cartesian_product( bounds.x..(bounds.x + bounds.w));
|
||||
let pixels = pixel_iter.map(
|
||||
|coord| -> Vec3 {
|
||||
sample_pixel(
|
||||
Vec2i{x: coord.1, y: coord.0},
|
||||
scene,
|
||||
properties,
|
||||
img_size,
|
||||
rng,
|
||||
)
|
||||
}
|
||||
).collect();
|
||||
Self {
|
||||
_bounds: bounds,
|
||||
pixels
|
||||
}
|
||||
}
|
||||
pub fn render_line(
|
||||
bounds: Rect, y: i32, // bounding rect and line
|
||||
img_size: Vec2i,
|
||||
|
||||
Reference in New Issue
Block a user