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