Add Oren-Nayar and fix bugs
This commit is contained in:
parent
3a37a72f56
commit
745b7d2602
7 changed files with 137 additions and 28 deletions
|
|
@ -6,7 +6,12 @@ use plotters::{
|
|||
};
|
||||
use rand::{rngs::SmallRng, SeedableRng};
|
||||
use ray_tracing_core::prelude::*;
|
||||
use ray_tracing_material::{diffuse::DiffuseMaterial, mirror::Mirror};
|
||||
use ray_tracing_material::{
|
||||
diffuse::DiffuseMaterial,
|
||||
microfacet::{BeckmannDistribution, Microfacet},
|
||||
mirror::Mirror,
|
||||
oren_nayar::OrenNayar,
|
||||
};
|
||||
use rayon::iter::{IntoParallelIterator, ParallelExtend, ParallelIterator};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
|
@ -20,6 +25,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let m = DiffuseMaterial::new(color);
|
||||
generate_chart("diffuse.png", &m, 100, w_in)?;
|
||||
|
||||
let m = Microfacet::new(BeckmannDistribution::new(0.5), color);
|
||||
generate_chart("microfacet.png", &m, 100, w_in)?;
|
||||
|
||||
let m = OrenNayar::new(0.5, color);
|
||||
generate_chart("oren-nayar.png", &m, 100, w_in)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +53,6 @@ fn generate_chart<M: Material<SmallRng>>(
|
|||
let sample_histogram = create_historgram_sampled(m, 400, 400, executions, w_in);
|
||||
|
||||
let max = Float::max(eval_histogram.max(), sample_histogram.max());
|
||||
dbg!(max, eval_histogram.max(), sample_histogram.max());
|
||||
|
||||
let area = areas[0].titled("Evaled", ("sans-serif", 30))?;
|
||||
plot_material(&area, eval_histogram, max)?;
|
||||
|
|
@ -132,6 +142,7 @@ where
|
|||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
assert!(f >= 0.0 && f <= max && f.is_finite(), "{f}");
|
||||
let color = plotters::prelude::ViridisRGB::get_color_normalized(f, 0.0, max);
|
||||
if dir.y() < 0.0 {
|
||||
lower_area.draw_pixel((dir.x() as f64, dir.z() as f64), &color)?;
|
||||
|
|
@ -263,6 +274,18 @@ fn create_historgram_sampled<M: Material<SmallRng>>(
|
|||
.map_init(SmallRng::from_entropy, |rng, _| {
|
||||
let sample = m.sample(w_in, rng);
|
||||
|
||||
assert!(
|
||||
sample.color().r() >= 0.0
|
||||
&& sample.color().r().is_finite()
|
||||
&& sample.color().g() >= 0.0
|
||||
&& sample.color().g().is_finite()
|
||||
&& sample.color().b() >= 0.0
|
||||
&& sample.color().b().is_finite(),
|
||||
"w_in: {w_in:?}; w_out: {:?}; material: {m:?}; color: {:?}",
|
||||
sample.w_out(),
|
||||
sample.color()
|
||||
);
|
||||
|
||||
(sample.w_out(), sample.color())
|
||||
}),
|
||||
);
|
||||
|
|
@ -285,7 +308,17 @@ fn create_histogram_evaled<M: Material<SmallRng>>(
|
|||
.map_init(SmallRng::from_entropy, |rng, _| {
|
||||
let w_out = Dir3::sample_uniform_sphere(rng);
|
||||
|
||||
let color = m.eval(w_in, w_out, rng) * w_out.y() * 4.0 * FloatConsts::PI;
|
||||
let color = m.eval(w_in, w_out, rng) * w_out.y().abs() * 4.0 * FloatConsts::PI;
|
||||
|
||||
assert!(
|
||||
color.r() >= 0.0
|
||||
&& color.r().is_finite()
|
||||
&& color.g() >= 0.0
|
||||
&& color.g().is_finite()
|
||||
&& color.b() >= 0.0
|
||||
&& color.b().is_finite(),
|
||||
"w_in: {w_in:?}; w_out: {w_out:?}; material: {m:?}; color: {color:?}"
|
||||
);
|
||||
|
||||
(w_out, color)
|
||||
}),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue