From 1e83ea211055eb234b89c69b5d03602e3fcb98fb Mon Sep 17 00:00:00 2001 From: Julian T Date: Fri, 5 Feb 2021 20:17:20 +0100 Subject: Achieve anti aliasing with multi pixel sampling --- src/sample/uniform.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/sample/uniform.rs (limited to 'src/sample/uniform.rs') diff --git a/src/sample/uniform.rs b/src/sample/uniform.rs new file mode 100644 index 0000000..221fdf8 --- /dev/null +++ b/src/sample/uniform.rs @@ -0,0 +1,32 @@ +use crate::core::Vector2f; +use crate::Float; +use super::Sampler; + +use rand::prelude::*; +use rand::distributions::Uniform; +use rand_pcg::Pcg32; + +#[derive(Clone)] +pub struct UniformSampler { + r: Pcg32, + d: Uniform, +} + +impl UniformSampler { + pub fn new() -> Self { + Self { + r: Pcg32::seed_from_u64(1), + d: Uniform::from(0.0..1.0), + } + } +} + +impl Sampler for UniformSampler { + fn get_sample(&mut self) -> Float { + self.d.sample(&mut self.r) + } + + fn get_sample_2d(&mut self) -> Vector2f { + Vector2f::new_xy(self.get_sample(), self.get_sample()) + } +} -- cgit v1.2.3