diff options
author | Julian T <julian@jtle.dk> | 2021-02-09 20:00:52 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-02-09 20:00:52 +0100 |
commit | 3a144c8c1fc83150fc06d792082db5cc4bce3cc5 (patch) | |
tree | e408c35a782c8595f2704c4d4dbff3424035ce82 /src/render/task.rs | |
parent | bb5d37b3685ae8da38865f837cf697dac0055b9d (diff) |
Add tiling for rendering
Diffstat (limited to 'src/render/task.rs')
-rw-r--r-- | src/render/task.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/render/task.rs b/src/render/task.rs new file mode 100644 index 0000000..017fe24 --- /dev/null +++ b/src/render/task.rs @@ -0,0 +1,49 @@ +//! Implements the main render loop +//! +//! This is not a final design +use crate::camera::film::FilmTile; +use crate::camera::Camera; +use crate::trace::{DefaultTracer, Tracer}; +use crate::sample::Sampler; + +use crate::core::{Vector2f}; +use crate::Float; + +pub struct RenderTask { + pub tile: Box<FilmTile>, + samples: u32, + pub tile_index: i32, +} + +pub struct RenderContext<'a> { + pub cam: &'a Camera, + pub trc: &'a DefaultTracer<'a>, +} + +impl RenderTask { + pub fn new(tile: Box<FilmTile>, samples: u32, tile_index: i32) -> Self { + Self { tile, samples, tile_index } + } + + fn render_at(&mut self, ctx: &RenderContext, x: i32, y: i32, sampler: &mut dyn Sampler) { + let corner = Vector2f::new_xy(x as Float, y as Float); + + for _ in 0..self.samples { + let p = corner + sampler.get_sample_2d(); + + // Create a ray + let (r, _) = ctx.cam.generate_ray(&p, sampler); + + self.tile.add_sample(&p, ctx.trc.trace(sampler, &r)); + } + } + + pub fn render(&mut self, ctx: &RenderContext, sampler: &mut dyn Sampler) { + let b = self.tile.bounds.clone(); + for y in b.min.y .. b.max.y { + for x in b.min.x .. b.max.x { + self.render_at(ctx, x, y, sampler); + } + } + } +} |