Skip to content

Commit

Permalink
chore: rename Sample -> Randomness
Browse files Browse the repository at this point in the history
  • Loading branch information
Walther committed Jun 9, 2024
1 parent 9f59840 commit 41d56de
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions clovers-cli/src/draw_cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Srgb>` as a pixelbuffer.
pub fn draw(opts: RenderOpts, scene: &Scene, sampler: Sampler) -> Vec<Srgb<u8>> {
Expand Down Expand Up @@ -67,7 +67,7 @@ fn render_pixel(
let max_depth = opts.max_depth;
let mut pixel_color: Xyz<E> = Xyz::new(0.0, 0.0, 0.0);
for sample in 0..opts.samples {
let Sample {
let Randomness {
pixel_offset,
lens_offset,
time,
Expand Down
5 changes: 3 additions & 2 deletions clovers-cli/src/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions clovers-cli/src/sampler/blue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions clovers-cli/src/sampler/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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,
Expand Down

0 comments on commit 41d56de

Please sign in to comment.