diff options
author | Julian T <julian@jtle.dk> | 2021-02-05 20:17:20 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-02-05 20:17:20 +0100 |
commit | 1e83ea211055eb234b89c69b5d03602e3fcb98fb (patch) | |
tree | 7b58c7e6d7d174906541e9f2acf546294f8e9ca5 /src/render.rs | |
parent | 9235e74dfbc41895a5f8807e1ab93508268a39ea (diff) |
Achieve anti aliasing with multi pixel sampling
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); } } } |