Compare commits

..

No commits in common. "6ba9add6eae6c26a2a24997b1e07a1060f7c05e0" and "aa5676865545fc4259ee8b3aeed16e2f69296290" have entirely different histories.

4 changed files with 25 additions and 53 deletions

View File

@ -9,7 +9,7 @@ use crate::{
camera::OrbitalCamera,
ray::Ray,
render::lines::{LookParams, Mesh, Pipeline, Vertex},
trace::{Hit, Scene, Source, Sphere},
trace::{Scene, Source, Sphere},
};
mod camera;
@ -156,7 +156,12 @@ impl Core {
depth_slice: None,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
load: wgpu::LoadOp::Clear(wgpu::Color {
r: 0.1,
g: 0.2,
b: 0.8,
a: 1.0,
}),
store: wgpu::StoreOp::Store,
},
})],
@ -205,9 +210,9 @@ impl Core {
let mut prng = rand_pcg::Pcg64::new(42, 0);
let source_rays: Vec<Ray> = (0..10240).map(|_| source.make_ray(&mut prng)).collect();
let camera_rays: Vec<Ray> = (0..10240).map(|_| camera.make_ray(&mut prng)).collect();
let camera_rays: Vec<Ray> = (0..1024).map(|_| camera.make_ray(&mut prng)).collect();
let mut source_ray_display: Vec<Vertex> = Vec::with_capacity(source_rays.len());
let mut hits: Vec<Hit> = Vec::with_capacity(source_rays.len());
let mut hits: Vec<Ray> = Vec::with_capacity(source_rays.len());
for ray in source_rays {
if let Some(hit) = scene.trace_ray(ray) {
hits.push(hit);
@ -221,11 +226,11 @@ impl Core {
color: vec3(0., 1., 0.),
},
Vertex {
pos: hit.incident.base - 0.02 * hit.incident.dir,
pos: hit.base - 0.02 * hit.dir,
color: vec3(0., 0., 1.),
},
Vertex {
pos: hit.incident.base,
pos: hit.base,
color: vec3(1., 1., 1.),
},
]);
@ -251,21 +256,15 @@ impl Core {
};
let mut value = 0.0f32;
for light_hit in &hits {
let d2 = hit.incident.base.distance_squared(light_hit.incident.base);
if d2 > 3. * sigma2 {
continue;
}
assert!(hit.incident.dir.is_normalized());
let radiance = hit.normal.dot(-hit.incident.dir);
let d2 = hit.base.distance_squared(light_hit.base);
let w = (-0.5 * d2 / sigma2).exp();
value += w * radiance;
value += w;
}
value *= weight;
value = 3. * (1. - (1. + value).recip());
let r = args.accum_sigma;
let r = 0.01;
let color = vec3(value, value - 1., value - 2.).clamp(Vec3::splat(0.), Vec3::splat(1.));
let vertex = |off: Vec3| Vertex {
pos: hit.incident.base + r * off,
pos: hit.base + r * off,
color,
};
camera_ray_display.extend([

View File

@ -78,14 +78,8 @@ pub struct Sphere {
pub radius: f32,
}
struct Hit1 {
pos: Vec3,
dist: f32,
normal: Vec3,
}
impl Sphere {
fn trace_ray(&self, ray: Ray) -> Option<Hit1> {
fn trace_ray(&self, ray: Ray) -> Option<f32> {
// let t: f32;
// let hit = ray.base + t * ray.dir;
// (hit - self.position).length() == self.radius;
@ -100,10 +94,7 @@ impl Sphere {
if d4 < 0. {
return None;
}
let dist = (-b2 - d4.sqrt()) / a;
let pos = ray.advance(dist).base;
let normal = (pos - self.position).normalize();
Some(Hit1 { pos, dist, normal })
Some((-b2 - d4.sqrt()) / a)
}
}
@ -112,25 +103,13 @@ pub struct Scene {
pub objects: Vec<Sphere>,
}
#[derive(Debug, Clone, Copy)]
pub struct Hit {
pub incident: Ray,
pub normal: Vec3,
}
impl Scene {
pub fn trace_ray(&self, ray: Ray) -> Option<Hit> {
let hit = self
pub fn trace_ray(&self, ray: Ray) -> Option<Ray> {
let dist = self
.objects
.iter()
.filter_map(|obj| obj.trace_ray(ray))
.min_by(|a, b| f32::total_cmp(&a.dist, &b.dist))?;
Some(Hit {
incident: Ray {
base: hit.pos,
dir: ray.dir,
},
normal: hit.normal,
})
.min_by(f32::total_cmp);
Some(ray.advance(dist?))
}
}

View File

@ -36,8 +36,8 @@ void PhotonLight::updateView() {
m_ui->cameraPitchLabel->setText(tr("Pitch: %1 deg").arg(QString::number(qRadiansToDegrees(args.camera_position.pitch))));
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->accumSigmaLabel->setText(tr("Sigma: %1").arg(QString::number(args.accum_sigma, 'f', 3)));
m_ui->accumScaleLabel->setText(tr("Scale: %1").arg(QString::number(args.accum_scale, 'f', 3)));
m_ui->accumSigmaLabel->setText(tr("Sigma: %1").arg(QString::number(args.accum_sigma)));
m_ui->accumScaleLabel->setText(tr("Scale: %1").arg(QString::number(args.accum_scale)));
m_ui->viewport->setView(args);
}

View File

@ -181,10 +181,7 @@
<number>-100</number>
</property>
<property name="maximum">
<number>0</number>
</property>
<property name="value">
<number>-40</number>
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -204,10 +201,7 @@
<number>-100</number>
</property>
<property name="maximum">
<number>0</number>
</property>
<property name="value">
<number>-50</number>
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>