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!
|
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 struct SphereParams {
|
||||||
pub radius: f32,
|
pub radius: f32,
|
||||||
|
pub color: Vec3,
|
||||||
pub alpha: f32,
|
pub alpha: f32,
|
||||||
pub glossiness: f32,
|
pub glossiness: f32,
|
||||||
pub origin: Vec3,
|
pub origin: Vec3,
|
||||||
|
|
@ -12,25 +13,27 @@ pub struct SphereParams {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SphereParamsDistribution {
|
pub struct SphereParamsDistribution {
|
||||||
pub rad: Uniform<f32>,
|
pub drad: Uniform<f32>,
|
||||||
pub pos: Uniform<f32>,
|
pub dpos: Uniform<f32>,
|
||||||
pub emit: Bernoulli,
|
pub dcol: Uniform<f32>,
|
||||||
pub ampl: Uniform<f32>,
|
pub demit: Bernoulli,
|
||||||
pub freq: Uniform<f32>,
|
pub dampl: Uniform<f32>,
|
||||||
pub phase: Uniform<f32>,
|
pub dfreq: Uniform<f32>,
|
||||||
pub gloss: Uniform<f32>,
|
pub dphase: Uniform<f32>,
|
||||||
|
pub dgloss: Uniform<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for SphereParamsDistribution {
|
impl Default for SphereParamsDistribution {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
rad: Uniform::new(-6., -4.),
|
drad: Uniform::new(0.01, 0.10),
|
||||||
pos: Uniform::new(-1.0, 1.0),
|
dpos: Uniform::new(-1.0, 1.0),
|
||||||
emit: Bernoulli::new(0.1).unwrap(),
|
dcol: Uniform::new(0.0, 1.0),
|
||||||
ampl: Uniform::new(0.3, 0.8),
|
demit: Bernoulli::new(0.1).unwrap(),
|
||||||
freq: Uniform::new(0.2, 1.5),
|
dampl: Uniform::new(0.3, 0.8),
|
||||||
phase: Uniform::new(0., 2. * std::f32::consts::PI),
|
dfreq: Uniform::new(0.2, 1.5),
|
||||||
gloss: Uniform::new(0., 1.),
|
dphase: Uniform::new(0., 2. * std::f32::consts::PI),
|
||||||
|
dgloss: Uniform::new(0., 1.),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -38,13 +41,14 @@ impl Default for SphereParamsDistribution {
|
||||||
impl SphereParamsDistribution {
|
impl SphereParamsDistribution {
|
||||||
pub fn make_params(&self, rgen: &mut impl rand::Rng) -> SphereParams {
|
pub fn make_params(&self, rgen: &mut impl rand::Rng) -> SphereParams {
|
||||||
SphereParams {
|
SphereParams {
|
||||||
origin: self.pos.sample3(rgen),
|
origin: self.dpos.sample3(rgen),
|
||||||
radius: 2.0f32.powf(self.rad.sample(rgen)),
|
radius: self.drad.sample(rgen),
|
||||||
alpha: if self.emit.sample(rgen) { 10.0 } else { 0.0 },
|
color: self.dcol.sample3(rgen).normalize(),
|
||||||
glossiness: self.gloss.sample(rgen),
|
alpha: if self.demit.sample(rgen) { 10.0 } else { 0.0 },
|
||||||
amplitudes: self.ampl.sample3(rgen),
|
glossiness: self.dgloss.sample(rgen),
|
||||||
frequencies: self.freq.sample3(rgen),
|
amplitudes: self.dampl.sample3(rgen),
|
||||||
phases: self.phase.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 {
|
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 center = self.origin + self.amplitudes * (self.frequencies * time + self.phases).map(|x| x.sin());
|
||||||
let radius = self.radius;
|
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 glossiness = self.glossiness;
|
||||||
let reflect_color = Vec3::splat(0.8);
|
let reflect_color = 0.6 * self.color + Vec3::splat(0.2);
|
||||||
crate::Sphere {
|
crate::Sphere {
|
||||||
center,
|
center,
|
||||||
radius,
|
radius,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user