add interreflections
This commit is contained in:
parent
5a69a3a1cb
commit
e80e1d09fe
49
src/lib.rs
49
src/lib.rs
|
|
@ -36,6 +36,7 @@ pub struct RedrawArgs {
|
|||
pub light_spread: f32,
|
||||
pub accum_sigma: f32,
|
||||
pub accum_scale: f32,
|
||||
pub reflections: u32,
|
||||
pub show_axes: bool,
|
||||
pub show_shapes: bool,
|
||||
pub show_hit_emission: bool,
|
||||
|
|
@ -261,29 +262,35 @@ impl Core {
|
|||
}
|
||||
}
|
||||
}
|
||||
let mut hits2: Vec<Hit> = Vec::with_capacity(hits.len());
|
||||
for hit in &hits {
|
||||
let reflector = Lambertian;
|
||||
let reflected = reflector.reflect(&mut prng, hit.normal, hit.incident.dir);
|
||||
let ray = Ray::new(hit.incident.base, reflected);
|
||||
let Some(hit2) = scene.trace_ray(ray) else {
|
||||
continue;
|
||||
};
|
||||
hits2.push(hit2);
|
||||
if args.show_indirect_hit {
|
||||
source_ray_display.extend([
|
||||
Vertex {
|
||||
pos: hit2.incident.base - 0.02 * hit2.incident.dir,
|
||||
color: vec3(1., 0., 1.),
|
||||
},
|
||||
Vertex {
|
||||
pos: hit2.incident.base,
|
||||
color: vec3(1., 1., 1.),
|
||||
},
|
||||
]);
|
||||
if args.reflections > 0 {
|
||||
let mut hits1 = hits.clone();
|
||||
for _ in 0..args.reflections {
|
||||
let mut hits2: Vec<Hit> = Vec::with_capacity(hits1.len());
|
||||
for hit in &hits1 {
|
||||
let reflector = Lambertian;
|
||||
let reflected = reflector.reflect(&mut prng, hit.normal, hit.incident.dir);
|
||||
let ray = Ray::new(hit.incident.base, reflected);
|
||||
let Some(hit2) = scene.trace_ray(ray) else {
|
||||
continue;
|
||||
};
|
||||
hits2.push(hit2);
|
||||
if args.show_indirect_hit {
|
||||
source_ray_display.extend([
|
||||
Vertex {
|
||||
pos: hit2.incident.base - 0.02 * hit2.incident.dir,
|
||||
color: vec3(1., 0., 1.),
|
||||
},
|
||||
Vertex {
|
||||
pos: hit2.incident.base,
|
||||
color: vec3(1., 1., 1.),
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
hits.extend(&hits2);
|
||||
hits1 = hits2;
|
||||
}
|
||||
}
|
||||
hits.extend(hits2);
|
||||
let mut camera_ray_display: Vec<Vertex> = Vec::with_capacity(camera_rays.len());
|
||||
if args.show_light {
|
||||
let sigma2 = args.accum_sigma.powi(2);
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ impl MainWindow {
|
|||
light_spread: 0.125,
|
||||
accum_sigma: 0.025,
|
||||
accum_scale: 0.01,
|
||||
reflections: 2,
|
||||
show_axes: true,
|
||||
show_shapes: true,
|
||||
show_hit_emission: false,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ struct RedrawArgs {
|
|||
float light_spread = 0.;
|
||||
float accum_sigma = 1.;
|
||||
float accum_scale = 1.;
|
||||
std::uint32_t reflections = 0;
|
||||
bool show_axes = true;
|
||||
bool show_shapes = true;
|
||||
bool show_hit_emission = true;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ void PhotonLight::updateView() {
|
|||
.light_spread = 0.125,
|
||||
.accum_sigma = exp10f(m_ui->accumSigma->value() / 25.0),
|
||||
.accum_scale = exp10f(m_ui->accumScale->value() / 25.0),
|
||||
.reflections = std::uint32_t(m_ui->reflections->value()),
|
||||
.show_axes = m_ui->displayAxes->isChecked(),
|
||||
.show_shapes = m_ui->displayShapes->isChecked(),
|
||||
.show_hit_emission = m_ui->displayEmitted->isChecked(),
|
||||
|
|
|
|||
|
|
@ -254,6 +254,23 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Reflections</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="reflections">
|
||||
<property name="maximum">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>2</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
@ -577,6 +594,22 @@
|
|||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>reflections</sender>
|
||||
<signal>valueChanged(int)</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>updateView()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>1489</x>
|
||||
<y>712</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>799</x>
|
||||
<y>599</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>updateView()</slot>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user