aboutsummaryrefslogtreecommitdiff
path: root/src/scene/scene.rs
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-02-08 14:32:11 +0100
committerJulian T <julian@jtle.dk>2021-02-08 14:32:11 +0100
commitdbe5f54957ddc13549a6ce822da95170aa09a0c6 (patch)
tree7cc45f25dd75cb7893fd0af49ae5353e38c5e392 /src/scene/scene.rs
parent6df0417568ef6f315138d9c3fd707ac3241a6a30 (diff)
Rename to pathtrace, started for of depth of field, choose closest intersect
Diffstat (limited to 'src/scene/scene.rs')
-rw-r--r--src/scene/scene.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/scene/scene.rs b/src/scene/scene.rs
index 8575217..83a43c7 100644
--- a/src/scene/scene.rs
+++ b/src/scene/scene.rs
@@ -7,6 +7,11 @@ pub struct Scene {
objs: Vec<Object>,
}
+pub struct SceneIntersect<'a> {
+ pub mat: &'a dyn Material,
+ pub i: Intersection,
+}
+
impl Scene {
pub fn new() -> Self {
Self {
@@ -24,14 +29,19 @@ impl Scene {
}
}
- pub fn intersect(&self, ray: &Ray) -> Option<(&dyn Material, Intersection)> {
+ pub fn intersect(&self, ray: &Ray) -> Option<SceneIntersect> {
+ let mut min: Option<SceneIntersect> = None;
+
for obj in self.objs.iter() {
if let Some(i) = obj.shape.intersect(&ray) {
- return Some((obj.mat.as_ref(), i))
+ match min {
+ Some(ref si) if si.i.t < i.t => (),
+ _ => min = Some(SceneIntersect {i, mat: obj.mat.as_ref() }),
+ }
}
}
- None
+ min
}
}