Compare commits

...

3 Commits

Author SHA1 Message Date
96e5c78a59 ui hints 2025-11-20 14:25:48 +03:00
e80e1d09fe add interreflections 2025-11-20 14:25:48 +03:00
5a69a3a1cb add custom display options 2025-11-20 14:25:48 +03:00
5 changed files with 481 additions and 124 deletions

View File

@ -36,6 +36,14 @@ 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_shapes: bool,
pub show_hit_emission: bool,
pub show_miss_emission: bool,
pub show_direct_hit: bool,
pub show_indirect_hit: bool,
pub show_light: bool,
} }
pub struct Gpu { pub struct Gpu {
@ -163,7 +171,9 @@ impl Core {
depth_stencil_attachment: None, depth_stencil_attachment: None,
..Default::default() ..Default::default()
}); });
if args.show_axes {
self.pipeline.render(&mut pass, [&self.tripod]); self.pipeline.render(&mut pass, [&self.tripod]);
}
let source = Source { let source = Source {
position_yaw: args.light_position.yaw, position_yaw: args.light_position.yaw,
@ -173,6 +183,7 @@ impl Core {
spread: args.light_spread, spread: args.light_spread,
}; };
if args.show_shapes {
let contour: Vec<Vertex> = loop_list(source.contour(17)) let contour: Vec<Vertex> = loop_list(source.contour(17))
.map(|pos| Vertex { .map(|pos| Vertex {
pos, pos,
@ -181,6 +192,7 @@ impl Core {
.collect(); .collect();
self.pipeline self.pipeline
.render(&mut pass, [&Mesh::new(&self.device, &contour)]); .render(&mut pass, [&Mesh::new(&self.device, &contour)]);
}
const BASE_R: f32 = 2.; const BASE_R: f32 = 2.;
const BASE_POS: Vec3 = vec3(0., 0., -BASE_R); const BASE_POS: Vec3 = vec3(0., 0., -BASE_R);
@ -211,6 +223,7 @@ impl Core {
for ray in source_rays { for ray in source_rays {
if let Some(hit) = scene.trace_ray(ray) { if let Some(hit) = scene.trace_ray(ray) {
hits.push(hit); hits.push(hit);
if args.show_hit_emission {
source_ray_display.extend([ source_ray_display.extend([
Vertex { Vertex {
pos: ray.base, pos: ray.base,
@ -220,6 +233,10 @@ impl Core {
pos: ray.base + 0.1 * ray.dir, pos: ray.base + 0.1 * ray.dir,
color: vec3(0., 1., 0.), color: vec3(0., 1., 0.),
}, },
]);
}
if args.show_direct_hit {
source_ray_display.extend([
Vertex { Vertex {
pos: hit.incident.base - 0.02 * hit.incident.dir, pos: hit.incident.base - 0.02 * hit.incident.dir,
color: vec3(0., 0., 1.), color: vec3(0., 0., 1.),
@ -229,7 +246,9 @@ impl Core {
color: vec3(1., 1., 1.), color: vec3(1., 1., 1.),
}, },
]); ]);
}
} else { } else {
if args.show_miss_emission {
source_ray_display.extend([ source_ray_display.extend([
Vertex { Vertex {
pos: ray.base, pos: ray.base,
@ -242,8 +261,12 @@ impl Core {
]); ]);
} }
} }
let mut hits2: Vec<Hit> = Vec::with_capacity(hits.len()); }
for hit in &hits { 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 reflector = Lambertian;
let reflected = reflector.reflect(&mut prng, hit.normal, hit.incident.dir); let reflected = reflector.reflect(&mut prng, hit.normal, hit.incident.dir);
let ray = Ray::new(hit.incident.base, reflected); let ray = Ray::new(hit.incident.base, reflected);
@ -251,6 +274,7 @@ impl Core {
continue; continue;
}; };
hits2.push(hit2); hits2.push(hit2);
if args.show_indirect_hit {
source_ray_display.extend([ source_ray_display.extend([
Vertex { Vertex {
pos: hit2.incident.base - 0.02 * hit2.incident.dir, pos: hit2.incident.base - 0.02 * hit2.incident.dir,
@ -262,8 +286,13 @@ impl Core {
}, },
]); ]);
} }
hits.extend(hits2); }
hits.extend(&hits2);
hits1 = 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 {
let sigma2 = args.accum_sigma.powi(2); let sigma2 = args.accum_sigma.powi(2);
let accum_normalizator = (2. * PI * sigma2).sqrt().recip(); let accum_normalizator = (2. * PI * sigma2).sqrt().recip();
for ray in camera_rays { for ray in camera_rays {
@ -303,10 +332,15 @@ impl Core {
vertex(Vec3::Z), vertex(Vec3::Z),
]); ]);
} }
}
if !source_ray_display.is_empty() {
self.pipeline self.pipeline
.render(&mut pass, [&Mesh::new(&self.device, &source_ray_display)]); .render(&mut pass, [&Mesh::new(&self.device, &source_ray_display)]);
}
if !camera_ray_display.is_empty() {
self.pipeline self.pipeline
.render(&mut pass, [&Mesh::new(&self.device, &camera_ray_display)]); .render(&mut pass, [&Mesh::new(&self.device, &camera_ray_display)]);
}
drop(pass); drop(pass);
self.queue.submit(std::iter::once(encoder.finish())); self.queue.submit(std::iter::once(encoder.finish()));

View File

@ -52,6 +52,14 @@ 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_shapes: true,
show_hit_emission: false,
show_miss_emission: false,
show_direct_hit: false,
show_indirect_hit: false,
show_light: true,
}), }),
_ => {} _ => {}
} }

View File

@ -20,6 +20,14 @@ 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_shapes = true;
bool show_hit_emission = true;
bool show_miss_emission = true;
bool show_direct_hit = true;
bool show_indirect_hit = true;
bool show_light = true;
}; };
} // namespace ffi } // namespace ffi

View File

@ -20,24 +20,34 @@ void PhotonLight::updateView() {
.camera_position = SphericalPosition{ .camera_position = SphericalPosition{
.yaw = deg_to_rad(m_ui->cameraYaw->value()), .yaw = deg_to_rad(m_ui->cameraYaw->value()),
.pitch = deg_to_rad(m_ui->cameraPitch->value()), .pitch = deg_to_rad(m_ui->cameraPitch->value()),
.distance = 3.0, .distance = m_ui->cameraDistance->value() / 10.0f,
}, },
.light_position = SphericalPosition{ .light_position = SphericalPosition{
.yaw = deg_to_rad(m_ui->lightYaw->value()), .yaw = deg_to_rad(m_ui->lightYaw->value()),
.pitch = deg_to_rad(m_ui->lightPitch->value()), .pitch = deg_to_rad(m_ui->lightPitch->value()),
.distance = 1.0, .distance = m_ui->lightDistance->value() / 10.0f,
}, },
.light_radius = 0.125, .light_radius = 0.125,
.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_shapes = m_ui->displayShapes->isChecked(),
.show_hit_emission = m_ui->displayEmitted->isChecked(),
.show_miss_emission = m_ui->displayEmitted->isChecked(),
.show_direct_hit = m_ui->displayDirectHits->isChecked(),
.show_indirect_hit = m_ui->displayIndirectHits->isChecked(),
.show_light = m_ui->displayResult->isChecked(),
}; };
m_ui->cameraYawLabel->setText(tr("Yaw: %1 deg").arg(QString::number(qRadiansToDegrees(args.camera_position.yaw)))); m_ui->cameraYawLabel->setText(tr("Yaw: %1 deg").arg(QString::number(qRadiansToDegrees(args.camera_position.yaw))));
m_ui->cameraPitchLabel->setText(tr("Pitch: %1 deg").arg(QString::number(qRadiansToDegrees(args.camera_position.pitch)))); m_ui->cameraPitchLabel->setText(tr("Pitch: %1 deg").arg(QString::number(qRadiansToDegrees(args.camera_position.pitch))));
m_ui->cameraDistanceLabel->setText(tr("Distance: %1").arg(QString::number(args.camera_position.distance)));
m_ui->lightYawLabel->setText(tr("Yaw: %1 deg").arg(QString::number(qRadiansToDegrees(args.light_position.yaw)))); m_ui->lightYawLabel->setText(tr("Yaw: %1 deg").arg(QString::number(qRadiansToDegrees(args.light_position.yaw))));
m_ui->lightPitchLabel->setText(tr("Pitch: %1 deg").arg(QString::number(qRadiansToDegrees(args.light_position.pitch)))); m_ui->lightPitchLabel->setText(tr("Pitch: %1 deg").arg(QString::number(qRadiansToDegrees(args.light_position.pitch))));
m_ui->accumSigmaLabel->setText(tr("Sigma: %1").arg(QString::number(args.accum_sigma, 'f', 3))); m_ui->lightDistanceLabel->setText(tr("Distance: %1").arg(QString::number(args.light_position.distance)));
m_ui->accumScaleLabel->setText(tr("Scale: %1").arg(QString::number(args.accum_scale, 'f', 3))); m_ui->accumSigmaLabel->setText(tr("Averaging radius: %1").arg(QString::number(args.accum_sigma, 'f', 3)));
m_ui->accumScaleLabel->setText(tr("Brightness: %1").arg(QString::number(args.accum_scale, 'f', 3)));
m_ui->viewport->setView(args); m_ui->viewport->setView(args);
} }

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>800</width> <width>1600</width>
<height>600</height> <height>1200</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -25,7 +25,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>800</width> <width>1600</width>
<height>38</height> <height>38</height>
</rect> </rect>
</property> </property>
@ -51,6 +51,9 @@
<property name="text"> <property name="text">
<string>Yaw</string> <string>Yaw</string>
</property> </property>
<property name="buddy">
<cstring>cameraYaw</cstring>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -77,6 +80,9 @@
<property name="text"> <property name="text">
<string>Pitch</string> <string>Pitch</string>
</property> </property>
<property name="buddy">
<cstring>cameraPitch</cstring>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -98,6 +104,29 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="cameraDistanceLabel">
<property name="text">
<string>Distance</string>
</property>
<property name="buddy">
<cstring>cameraDistance</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="cameraDistance">
<property name="maximum">
<number>50</number>
</property>
<property name="value">
<number>30</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -112,6 +141,9 @@
<property name="text"> <property name="text">
<string>Yaw</string> <string>Yaw</string>
</property> </property>
<property name="buddy">
<cstring>lightYaw</cstring>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -135,6 +167,9 @@
<property name="text"> <property name="text">
<string>Pitch</string> <string>Pitch</string>
</property> </property>
<property name="buddy">
<cstring>lightPitch</cstring>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -159,19 +194,45 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="lightDistanceLabel">
<property name="text">
<string>Distance</string>
</property>
<property name="buddy">
<cstring>lightDistance</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="lightDistance">
<property name="maximum">
<number>50</number>
</property>
<property name="value">
<number>10</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="groupBox_3"> <widget class="QGroupBox" name="groupBox_3">
<property name="title"> <property name="title">
<string>Accumulating</string> <string>Lighting</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
<item> <item>
<widget class="QLabel" name="accumSigmaLabel"> <widget class="QLabel" name="accumSigmaLabel">
<property name="text"> <property name="text">
<string>Sigma</string> <string>Averaging radius</string>
</property>
<property name="buddy">
<cstring>accumSigma</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@ -194,7 +255,10 @@
<item> <item>
<widget class="QLabel" name="accumScaleLabel"> <widget class="QLabel" name="accumScaleLabel">
<property name="text"> <property name="text">
<string>Scale</string> <string>Brightness</string>
</property>
<property name="buddy">
<cstring>accumScale</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@ -214,6 +278,95 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Reflections</string>
</property>
<property name="buddy">
<cstring>reflections</cstring>
</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>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Show</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QCheckBox" name="displayAxes">
<property name="text">
<string>Axes</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="displayShapes">
<property name="text">
<string>Shapes</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="displayEmitted">
<property name="text">
<string>Emitted rays</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="displayDirectHits">
<property name="text">
<string>Direct incident rays</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="displayIndirectHits">
<property name="text">
<string>Indirect incident rays</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="displayResult">
<property name="text">
<string>Average light</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -251,8 +404,8 @@
<slot>updateView()</slot> <slot>updateView()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>688</x> <x>1585</x>
<y>159</y> <y>169</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>403</x> <x>403</x>
@ -267,8 +420,8 @@
<slot>updateView()</slot> <slot>updateView()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>688</x> <x>1585</x>
<y>215</y> <y>225</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>403</x> <x>403</x>
@ -283,8 +436,8 @@
<slot>updateView()</slot> <slot>updateView()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>688</x> <x>1585</x>
<y>319</y> <y>385</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>403</x> <x>403</x>
@ -299,8 +452,8 @@
<slot>updateView()</slot> <slot>updateView()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>688</x> <x>1585</x>
<y>375</y> <y>441</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>403</x> <x>403</x>
@ -315,8 +468,8 @@
<slot>updateView()</slot> <slot>updateView()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>729</x> <x>1585</x>
<y>479</y> <y>601</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -331,8 +484,8 @@
<slot>updateView()</slot> <slot>updateView()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>729</x> <x>1585</x>
<y>535</y> <y>657</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -340,6 +493,150 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>cameraDistance</sender>
<signal>valueChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>updateView()</slot>
<hints>
<hint type="sourcelabel">
<x>1489</x>
<y>271</y>
</hint>
<hint type="destinationlabel">
<x>799</x>
<y>599</y>
</hint>
</hints>
</connection>
<connection>
<sender>lightDistance</sender>
<signal>valueChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>updateView()</slot>
<hints>
<hint type="sourcelabel">
<x>1489</x>
<y>487</y>
</hint>
<hint type="destinationlabel">
<x>799</x>
<y>599</y>
</hint>
</hints>
</connection>
<connection>
<sender>displayAxes</sender>
<signal>stateChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>updateView()</slot>
<hints>
<hint type="sourcelabel">
<x>1489</x>
<y>799</y>
</hint>
<hint type="destinationlabel">
<x>799</x>
<y>599</y>
</hint>
</hints>
</connection>
<connection>
<sender>displayDirectHits</sender>
<signal>stateChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>updateView()</slot>
<hints>
<hint type="sourcelabel">
<x>1489</x>
<y>901</y>
</hint>
<hint type="destinationlabel">
<x>799</x>
<y>599</y>
</hint>
</hints>
</connection>
<connection>
<sender>displayEmitted</sender>
<signal>stateChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>updateView()</slot>
<hints>
<hint type="sourcelabel">
<x>1489</x>
<y>867</y>
</hint>
<hint type="destinationlabel">
<x>799</x>
<y>599</y>
</hint>
</hints>
</connection>
<connection>
<sender>displayIndirectHits</sender>
<signal>stateChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>updateView()</slot>
<hints>
<hint type="sourcelabel">
<x>1489</x>
<y>935</y>
</hint>
<hint type="destinationlabel">
<x>799</x>
<y>599</y>
</hint>
</hints>
</connection>
<connection>
<sender>displayResult</sender>
<signal>stateChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>updateView()</slot>
<hints>
<hint type="sourcelabel">
<x>1489</x>
<y>969</y>
</hint>
<hint type="destinationlabel">
<x>799</x>
<y>599</y>
</hint>
</hints>
</connection>
<connection>
<sender>displayShapes</sender>
<signal>stateChanged(int)</signal>
<receiver>MainWindow</receiver>
<slot>updateView()</slot>
<hints>
<hint type="sourcelabel">
<x>1489</x>
<y>833</y>
</hint>
<hint type="destinationlabel">
<x>799</x>
<y>599</y>
</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> </connections>
<slots> <slots>
<slot>updateView()</slot> <slot>updateView()</slot>