Simplify sphere parameter generation
This commit is contained in:
parent
aede1ef03e
commit
3767f44468
|
|
@ -11,41 +11,22 @@ pub struct SphereParams {
|
||||||
pub phases: Vec3,
|
pub phases: Vec3,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SphereParamsDistribution {
|
pub fn distr<R: rand::Rng>() -> impl Fn(&mut R) -> SphereParams {
|
||||||
pub rad: Uniform<f32>,
|
let rad = Uniform::new(-6., -4.);
|
||||||
pub pos: Uniform<f32>,
|
let pos = Uniform::new(-1.0, 1.0);
|
||||||
pub emit: Bernoulli,
|
let emit = Bernoulli::new(0.1).unwrap();
|
||||||
pub ampl: Uniform<f32>,
|
let ampl = Uniform::new(0.3, 0.8);
|
||||||
pub freq: Uniform<f32>,
|
let freq = Uniform::new(0.2, 1.5);
|
||||||
pub phase: Uniform<f32>,
|
let phase = Uniform::new(0., 2. * std::f32::consts::PI);
|
||||||
pub gloss: Uniform<f32>,
|
let gloss = Uniform::new(0., 1.);
|
||||||
}
|
move |rgen| SphereParams {
|
||||||
|
origin: pos.sample3(rgen),
|
||||||
impl Default for SphereParamsDistribution {
|
radius: 2.0f32.powf(rad.sample(rgen)),
|
||||||
fn default() -> Self {
|
alpha: if emit.sample(rgen) { 10.0 } else { 0.0 },
|
||||||
Self {
|
glossiness: gloss.sample(rgen),
|
||||||
rad: Uniform::new(-6., -4.),
|
amplitudes: ampl.sample3(rgen),
|
||||||
pos: Uniform::new(-1.0, 1.0),
|
frequencies: freq.sample3(rgen),
|
||||||
emit: Bernoulli::new(0.1).unwrap(),
|
phases: phase.sample3(rgen),
|
||||||
ampl: Uniform::new(0.3, 0.8),
|
|
||||||
freq: Uniform::new(0.2, 1.5),
|
|
||||||
phase: Uniform::new(0., 2. * std::f32::consts::PI),
|
|
||||||
gloss: Uniform::new(0., 1.),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SphereParamsDistribution {
|
|
||||||
pub fn make_params(&self, rgen: &mut impl rand::Rng) -> SphereParams {
|
|
||||||
SphereParams {
|
|
||||||
origin: self.pos.sample3(rgen),
|
|
||||||
radius: 2.0f32.powf(self.rad.sample(rgen)),
|
|
||||||
alpha: if self.emit.sample(rgen) { 10.0 } else { 0.0 },
|
|
||||||
glossiness: self.gloss.sample(rgen),
|
|
||||||
amplitudes: self.ampl.sample3(rgen),
|
|
||||||
frequencies: self.freq.sample3(rgen),
|
|
||||||
phases: self.phase.sample3(rgen),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,8 @@ fn main() {
|
||||||
let mut tracer = Tracer::new(&device, hdr_format);
|
let mut tracer = Tracer::new(&device, hdr_format);
|
||||||
let sphere_params: Vec<_> = {
|
let sphere_params: Vec<_> = {
|
||||||
let mut rng = rand_pcg::Pcg32::new(42, 0);
|
let mut rng = rand_pcg::Pcg32::new(42, 0);
|
||||||
let distr = anim::SphereParamsDistribution::default();
|
let distr = anim::distr();
|
||||||
(0..N_SPHERES).map(|_| distr.make_params(&mut rng)).collect()
|
(0..N_SPHERES).map(|_| distr(&mut rng)).collect()
|
||||||
};
|
};
|
||||||
let tracer_env = TracerEnv::new(&device, &tracer, &envmap);
|
let tracer_env = TracerEnv::new(&device, &tracer, &envmap);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user