diff options
Diffstat (limited to 'src/render.rs')
-rw-r--r-- | src/render.rs | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/render.rs b/src/render.rs index 7d05aba..c8a75da 100644 --- a/src/render.rs +++ b/src/render.rs @@ -5,8 +5,9 @@ use crate::camera::film::FilmTile; use crate::camera::Camera; use crate::scene::Scene; use crate::trace::Tracer; +use crate::sample::Sampler; -use crate::core::{Vector2f, Vector3f, Spectrum}; +use crate::core::{Vector2f, Spectrum}; use crate::Float; pub struct RenderTask { @@ -25,20 +26,24 @@ impl RenderTask { Self { tile, samples } } - fn render_at(&self, ctx: &RenderContext, x: i32, y: i32) -> Spectrum { - // Create a ray - let (r, _) = ctx.cam.generate_ray(&Vector2f::new_xy(x as Float, y as Float)); + 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); - ctx.trc.trace(ctx.scn, &r) + for _ in 0..self.samples { + let p = corner + sampler.get_sample_2d(); + + // Create a ray + let (r, _) = ctx.cam.generate_ray(&p); + + self.tile.add_sample(&p, ctx.trc.trace(ctx.scn, &r)); + } } - pub fn render(&mut self, ctx: &RenderContext) { + pub fn render(&mut self, ctx: &RenderContext, sampler: &mut dyn Sampler) { let b = self.tile.bounds.clone(); for x in b.min.x .. b.max.x { for y in b.min.y .. b.max.y { - let p = Vector2f::new_xy(x as Float, y as Float); - - self.tile.add_sample(&p, self.render_at(ctx, x, y)) + self.render_at(ctx, x, y, sampler); } } } |