Add eval to visualizer and fix pbr error
This commit is contained in:
parent
109a72c19a
commit
3a37a72f56
10 changed files with 105 additions and 55 deletions
|
|
@ -8,7 +8,7 @@ pub trait Material<R: Rng>: Sync + Debug {
|
|||
fn sample(&self, w_in: Dir3, rng: &mut R) -> SampleResult {
|
||||
let w_out = Dir3::sample_cosine_hemisphere(rng);
|
||||
|
||||
SampleResult::new(w_out, self.eval(w_in, w_out, rng))
|
||||
SampleResult::new(w_out, self.eval(w_in, w_out, rng) * FloatConsts::PI)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,13 @@ impl Dir3 {
|
|||
Dir3::new(Float::sin(phi) * r, Float::cos(theta), Float::cos(phi) * r)
|
||||
}
|
||||
|
||||
pub fn sample_uniform_sphere<R: Rng>(rng: &mut R) -> Self {
|
||||
let theta = Float::acos(1.0 - 2.0 * rng.gen::<Float>());
|
||||
let phi = 2.0 * FloatConsts::PI * rng.gen::<Float>();
|
||||
let r = Float::sin(theta);
|
||||
Dir3::new(Float::sin(phi) * r, Float::cos(theta), Float::cos(phi) * r)
|
||||
}
|
||||
|
||||
pub fn sample_cosine_hemisphere<R: Rng>(rng: &mut R) -> Self {
|
||||
let mut d = Self::sample_disc(rng);
|
||||
d.y = Float::sqrt(Float::max(0.0, 1.0 - d.x * d.x - d.z * d.z));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue