Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Oom committed May 11, 2024
1 parent 993c849 commit b0a391e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
4 changes: 2 additions & 2 deletions scene/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ fn blend_from_mtl(image_directory: &Path, material: &mtl::Material) -> Arc<Mater
Arc::new(material)
}

fn materials_from_mtl<'p, 'm>(
image_directory: &'p Path,
fn materials_from_mtl<'m>(
image_directory: &Path,
mtl: &'m mtl::Mtl,
) -> BTreeMap<&'m str, Arc<MaterialModel>> {
mtl.materials
Expand Down
50 changes: 20 additions & 30 deletions tracing/src/raytracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{
};
use geometry::{intersection::RayIntersection, ray::Ray};
use kdtree::KdTree;
use nalgebra::{UnitVector3, Vector2, Vector3};
use scene::{camera::Pinhole, light::SphericalLight, Scene};
use nalgebra::{Vector2, Vector3};
use scene::{camera::Pinhole, material::MaterialModel, Scene};

pub struct Raytracer {
pub scene: Scene,
Expand All @@ -24,32 +24,6 @@ impl Raytracer {
self.intersect(ray, t_range).is_some()
}

fn light_contribution(
&self,
material: &dyn Material,
target: Vector3<f32>,
offset_point: Vector3<f32>,
wi: Vector3<f32>,
n: UnitVector3<f32>,
uv: Vector2<f32>,
light: &SphericalLight,
) -> Vector3<f32> {
let direction = light.center - target;
let shadow_ray = Ray {
origin: offset_point,
direction,
};
if self.intersect_any(&shadow_ray, 0.0..=1.0) {
return Vector3::zeros();
}
let wo = direction.normalize();
let radiance = light.emitted(target);
material
.brdf(&OutgoingRay { wi, n, wo, uv })
.component_mul(&radiance)
* wo.dot(&n).abs()
}

fn trace_ray(&self, ray: &Ray) -> Vector3<f32> {
let intersection = self.intersect(ray, 0.0..=f32::MAX);
if intersection.is_none() {
Expand All @@ -66,11 +40,27 @@ impl Raytracer {
// TODO: How to chose offset?
let offset_point = point + 0.0001 * n.into_inner();

let material = triangle.material.as_ref();
self.scene
.lights
.iter()
.map(|light| self.light_contribution(material, point, offset_point, wi, n, uv, light))
.map(|light| {
let this = &self;
let material: &MaterialModel = &triangle.material;
let direction = light.center - point;
let shadow_ray = Ray {
origin: offset_point,
direction,
};
if this.intersect_any(&shadow_ray, 0.0..=1.0) {
return Vector3::zeros();
}
let wo = direction.normalize();
let radiance = light.emitted(point);
material
.brdf(&OutgoingRay { wi, n, wo, uv })
.component_mul(&radiance)
* wo.dot(&n).abs()
})
.sum()
}

Expand Down

0 comments on commit b0a391e

Please sign in to comment.