Compare commits
No commits in common. "bb83f3bc4712295a14a9e0f20b370032a0e2da43" and "cb500033c06e041e976558593fb8dbd879077c26" have entirely different histories.
bb83f3bc47
...
cb500033c0
|
|
@ -3,4 +3,3 @@
|
|||
Basic GPU-side ray tracing example. `cargo run --bin envmap` to prepare the sky, then `cargo run` to see it moving!
|
||||
|
||||

|
||||

|
||||
|
|
|
|||
BIN
screenshot2.jpg
BIN
screenshot2.jpg
Binary file not shown.
|
Before Width: | Height: | Size: 265 KiB |
|
|
@ -3,6 +3,7 @@ use rand_distr::{Bernoulli, Distribution, Uniform};
|
|||
|
||||
pub struct SphereParams {
|
||||
pub radius: f32,
|
||||
pub color: Vec3,
|
||||
pub alpha: f32,
|
||||
pub glossiness: f32,
|
||||
pub origin: Vec3,
|
||||
|
|
@ -12,25 +13,27 @@ pub struct SphereParams {
|
|||
}
|
||||
|
||||
pub struct SphereParamsDistribution {
|
||||
pub rad: Uniform<f32>,
|
||||
pub pos: Uniform<f32>,
|
||||
pub emit: Bernoulli,
|
||||
pub ampl: Uniform<f32>,
|
||||
pub freq: Uniform<f32>,
|
||||
pub phase: Uniform<f32>,
|
||||
pub gloss: Uniform<f32>,
|
||||
pub drad: Uniform<f32>,
|
||||
pub dpos: Uniform<f32>,
|
||||
pub dcol: Uniform<f32>,
|
||||
pub demit: Bernoulli,
|
||||
pub dampl: Uniform<f32>,
|
||||
pub dfreq: Uniform<f32>,
|
||||
pub dphase: Uniform<f32>,
|
||||
pub dgloss: Uniform<f32>,
|
||||
}
|
||||
|
||||
impl Default for SphereParamsDistribution {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
rad: Uniform::new(-6., -4.),
|
||||
pos: Uniform::new(-1.0, 1.0),
|
||||
emit: Bernoulli::new(0.1).unwrap(),
|
||||
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.),
|
||||
drad: Uniform::new(0.01, 0.10),
|
||||
dpos: Uniform::new(-1.0, 1.0),
|
||||
dcol: Uniform::new(0.0, 1.0),
|
||||
demit: Bernoulli::new(0.1).unwrap(),
|
||||
dampl: Uniform::new(0.3, 0.8),
|
||||
dfreq: Uniform::new(0.2, 1.5),
|
||||
dphase: Uniform::new(0., 2. * std::f32::consts::PI),
|
||||
dgloss: Uniform::new(0., 1.),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -38,13 +41,14 @@ impl Default for SphereParamsDistribution {
|
|||
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),
|
||||
origin: self.dpos.sample3(rgen),
|
||||
radius: self.drad.sample(rgen),
|
||||
color: self.dcol.sample3(rgen).normalize(),
|
||||
alpha: if self.demit.sample(rgen) { 10.0 } else { 0.0 },
|
||||
glossiness: self.dgloss.sample(rgen),
|
||||
amplitudes: self.dampl.sample3(rgen),
|
||||
frequencies: self.dfreq.sample3(rgen),
|
||||
phases: self.dphase.sample3(rgen),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -53,9 +57,9 @@ impl SphereParams {
|
|||
pub fn to_sphere(&self, time: f32) -> crate::Sphere {
|
||||
let center = self.origin + self.amplitudes * (self.frequencies * time + self.phases).map(|x| x.sin());
|
||||
let radius = self.radius;
|
||||
let emit_color = self.alpha * vec3(0.9, 0.6, 0.1);
|
||||
let emit_color = self.alpha * self.color;
|
||||
let glossiness = self.glossiness;
|
||||
let reflect_color = Vec3::splat(0.8);
|
||||
let reflect_color = 0.6 * self.color + Vec3::splat(0.2);
|
||||
crate::Sphere {
|
||||
center,
|
||||
radius,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user