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 light_spread: f32,
|
||||||
pub accum_sigma: f32,
|
pub accum_sigma: f32,
|
||||||
pub accum_scale: f32,
|
pub accum_scale: f32,
|
||||||
|
pub reflections: u32,
|
||||||
pub show_axes: bool,
|
pub show_axes: bool,
|
||||||
pub show_shapes: bool,
|
pub show_shapes: bool,
|
||||||
pub show_hit_emission: bool,
|
pub show_hit_emission: bool,
|
||||||
|
|
@ -261,29 +262,35 @@ impl Core {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut hits2: Vec<Hit> = Vec::with_capacity(hits.len());
|
if args.reflections > 0 {
|
||||||
for hit in &hits {
|
let mut hits1 = hits.clone();
|
||||||
let reflector = Lambertian;
|
for _ in 0..args.reflections {
|
||||||
let reflected = reflector.reflect(&mut prng, hit.normal, hit.incident.dir);
|
let mut hits2: Vec<Hit> = Vec::with_capacity(hits1.len());
|
||||||
let ray = Ray::new(hit.incident.base, reflected);
|
for hit in &hits1 {
|
||||||
let Some(hit2) = scene.trace_ray(ray) else {
|
let reflector = Lambertian;
|
||||||
continue;
|
let reflected = reflector.reflect(&mut prng, hit.normal, hit.incident.dir);
|
||||||
};
|
let ray = Ray::new(hit.incident.base, reflected);
|
||||||
hits2.push(hit2);
|
let Some(hit2) = scene.trace_ray(ray) else {
|
||||||
if args.show_indirect_hit {
|
continue;
|
||||||
source_ray_display.extend([
|
};
|
||||||
Vertex {
|
hits2.push(hit2);
|
||||||
pos: hit2.incident.base - 0.02 * hit2.incident.dir,
|
if args.show_indirect_hit {
|
||||||
color: vec3(1., 0., 1.),
|
source_ray_display.extend([
|
||||||
},
|
Vertex {
|
||||||
Vertex {
|
pos: hit2.incident.base - 0.02 * hit2.incident.dir,
|
||||||
pos: hit2.incident.base,
|
color: vec3(1., 0., 1.),
|
||||||
color: vec3(1., 1., 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());
|
let mut camera_ray_display: Vec<Vertex> = Vec::with_capacity(camera_rays.len());
|
||||||
if args.show_light {
|
if args.show_light {
|
||||||
let sigma2 = args.accum_sigma.powi(2);
|
let sigma2 = args.accum_sigma.powi(2);
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ impl MainWindow {
|
||||||
light_spread: 0.125,
|
light_spread: 0.125,
|
||||||
accum_sigma: 0.025,
|
accum_sigma: 0.025,
|
||||||
accum_scale: 0.01,
|
accum_scale: 0.01,
|
||||||
|
reflections: 2,
|
||||||
show_axes: true,
|
show_axes: true,
|
||||||
show_shapes: true,
|
show_shapes: true,
|
||||||
show_hit_emission: false,
|
show_hit_emission: false,
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ struct RedrawArgs {
|
||||||
float light_spread = 0.;
|
float light_spread = 0.;
|
||||||
float accum_sigma = 1.;
|
float accum_sigma = 1.;
|
||||||
float accum_scale = 1.;
|
float accum_scale = 1.;
|
||||||
|
std::uint32_t reflections = 0;
|
||||||
bool show_axes = true;
|
bool show_axes = true;
|
||||||
bool show_shapes = true;
|
bool show_shapes = true;
|
||||||
bool show_hit_emission = true;
|
bool show_hit_emission = true;
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ void PhotonLight::updateView() {
|
||||||
.light_spread = 0.125,
|
.light_spread = 0.125,
|
||||||
.accum_sigma = exp10f(m_ui->accumSigma->value() / 25.0),
|
.accum_sigma = exp10f(m_ui->accumSigma->value() / 25.0),
|
||||||
.accum_scale = exp10f(m_ui->accumScale->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_axes = m_ui->displayAxes->isChecked(),
|
||||||
.show_shapes = m_ui->displayShapes->isChecked(),
|
.show_shapes = m_ui->displayShapes->isChecked(),
|
||||||
.show_hit_emission = m_ui->displayEmitted->isChecked(),
|
.show_hit_emission = m_ui->displayEmitted->isChecked(),
|
||||||
|
|
|
||||||
|
|
@ -254,6 +254,23 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
@ -577,6 +594,22 @@
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</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>
|
</connections>
|
||||||
<slots>
|
<slots>
|
||||||
<slot>updateView()</slot>
|
<slot>updateView()</slot>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user