From 41d56deb808fe553fc98457d8dbb93a99ac5e92c Mon Sep 17 00:00:00 2001 From: Walther Date: Sun, 9 Jun 2024 11:27:03 +0300 Subject: [PATCH] chore: rename Sample -> Randomness --- clovers-cli/src/draw_cpu.rs | 4 ++-- clovers-cli/src/sampler.rs | 5 +++-- clovers-cli/src/sampler/blue.rs | 4 ++-- clovers-cli/src/sampler/random.rs | 6 +++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/clovers-cli/src/draw_cpu.rs b/clovers-cli/src/draw_cpu.rs index 720dec12..cc3d52c1 100644 --- a/clovers-cli/src/draw_cpu.rs +++ b/clovers-cli/src/draw_cpu.rs @@ -16,7 +16,7 @@ use crate::colorize::colorize; use crate::normals::normal_map; use crate::sampler::blue::BlueSampler; use crate::sampler::random::RandomSampler; -use crate::sampler::{Sample, Sampler, SamplerTrait}; +use crate::sampler::{Randomness, Sampler, SamplerTrait}; /// The main drawing function, returns a `Vec` as a pixelbuffer. pub fn draw(opts: RenderOpts, scene: &Scene, sampler: Sampler) -> Vec> { @@ -67,7 +67,7 @@ fn render_pixel( let max_depth = opts.max_depth; let mut pixel_color: Xyz = Xyz::new(0.0, 0.0, 0.0); for sample in 0..opts.samples { - let Sample { + let Randomness { pixel_offset, lens_offset, time, diff --git a/clovers-cli/src/sampler.rs b/clovers-cli/src/sampler.rs index cf2862e2..e483908d 100644 --- a/clovers-cli/src/sampler.rs +++ b/clovers-cli/src/sampler.rs @@ -10,9 +10,10 @@ pub mod random; pub trait SamplerTrait<'scene> { // TODO: better types - fn sample(&mut self, i: i32, j: i32, index: i32) -> Sample; + fn sample(&mut self, i: i32, j: i32, index: i32) -> Randomness; /// Manually request a sample from the specific dimension + #[allow(dead_code)] // TODO: remove fn sample_dimension( &mut self, i: i32, @@ -23,7 +24,7 @@ pub trait SamplerTrait<'scene> { } /// A collection of random values to be used for each sample. Returned as a struct to ensure the correct sampling order for the underlying source of randomness. -pub struct Sample { +pub struct Randomness { /// Intra-pixel x,y offset. Used for antialiasing. pub pixel_offset: Vec2, /// The x,y offset used in the lens equations for aperture / depth-of-field simulation diff --git a/clovers-cli/src/sampler/blue.rs b/clovers-cli/src/sampler/blue.rs index 8bb00c8a..f3928e3d 100644 --- a/clovers-cli/src/sampler/blue.rs +++ b/clovers-cli/src/sampler/blue.rs @@ -31,7 +31,7 @@ impl<'scene> BlueSampler { } impl<'scene> SamplerTrait<'scene> for BlueSampler { - fn sample(&mut self, i: i32, j: i32, index: i32) -> Sample { + fn sample(&mut self, i: i32, j: i32, index: i32) -> Randomness { let pixel_offset = Vec2::new( (self.get)(i, j, index, SamplerDimension::PixelOffsetX), (self.get)(i, j, index, SamplerDimension::PixelOffsetY), @@ -44,7 +44,7 @@ impl<'scene> SamplerTrait<'scene> for BlueSampler { // TODO: verify uniformity & correctness for math? let wavelength = sample_wavelength((self.get)(i, j, index, SamplerDimension::Wavelength)); - Sample { + Randomness { pixel_offset, lens_offset, time, diff --git a/clovers-cli/src/sampler/random.rs b/clovers-cli/src/sampler/random.rs index 75aa6274..7c6d0467 100644 --- a/clovers-cli/src/sampler/random.rs +++ b/clovers-cli/src/sampler/random.rs @@ -3,7 +3,7 @@ use clovers::{random::random_in_unit_disk, wavelength::random_wavelength, Vec2}; use rand::{rngs::SmallRng, Rng}; -use super::{Sample, SamplerTrait}; +use super::{Randomness, SamplerTrait}; #[derive(Debug)] pub struct RandomSampler<'scene> { @@ -17,13 +17,13 @@ impl<'scene> RandomSampler<'scene> { } impl<'scene> SamplerTrait<'scene> for RandomSampler<'scene> { - fn sample(&mut self, _i: i32, _j: i32, _index: i32) -> Sample { + fn sample(&mut self, _i: i32, _j: i32, _index: i32) -> Randomness { let pixel_offset = Vec2::new(self.rng.gen(), self.rng.gen()); let lens_offset = random_in_unit_disk(self.rng).xy(); let time = self.rng.gen(); let wavelength = random_wavelength(self.rng); - Sample { + Randomness { pixel_offset, lens_offset, time,