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
|
// 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);
|
||||||
for row in (0..image.y).rev() {
|
let tile = Tile::render_tile(
|
||||||
let bounds = Rect{ // render boundary (a horizontal slice)
|
Rect { x: 0, y: 0, w: image.x, h: image.y },
|
||||||
x: 0,
|
image,
|
||||||
y: row,
|
&scene,
|
||||||
w: image.x,
|
&render_config,
|
||||||
h: 1
|
&mut small_rng
|
||||||
};
|
);
|
||||||
let tile = Tile::render_line(bounds, row, image, &scene, &render_config, &mut small_rng);
|
for pixel in tile.pixels.iter().rev() {
|
||||||
eprintln!("Printing scanline #{}", row);
|
println!("{}", pixel.print_ppm(render_config.samples));
|
||||||
for pixel in tile.pixels {
|
|
||||||
println!("{}", pixel.print_ppm(render_config.samples))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// TODO: Dispatcher shutdown mechanism. Right now, we might technically be leaking threads.
|
|
||||||
eprintln!("Done!");
|
eprintln!("Done!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ use crate::scene::{
|
|||||||
|
|
||||||
use rand::rngs::SmallRng;
|
use rand::rngs::SmallRng;
|
||||||
|
|
||||||
|
use itertools::{self, Itertools};
|
||||||
|
|
||||||
const SKY_COLOR: Vec3 = Vec3 { x: 0.5, y: 0.7, z: 1.0};
|
const SKY_COLOR: Vec3 = Vec3 { x: 0.5, y: 0.7, z: 1.0};
|
||||||
|
|
||||||
pub struct RenderProperties {
|
pub struct RenderProperties {
|
||||||
@@ -93,6 +95,31 @@ pub struct Tile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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(
|
pub fn render_line(
|
||||||
bounds: Rect, y: i32, // bounding rect and line
|
bounds: Rect, y: i32, // bounding rect and line
|
||||||
img_size: Vec2i,
|
img_size: Vec2i,
|
||||||
|
|||||||
Reference in New Issue
Block a user