Change Scene trait to account for material data

This commit is contained in:
hal8174 2025-08-22 21:48:07 +02:00
parent 76448ed442
commit 2bc5ec93fe
Signed by: hal8174
SSH key fingerprint: SHA256:NN98ZYwnrreQLSOV/g+amY7C3yL/mS1heD7bi5t6PPw
19 changed files with 306 additions and 124 deletions

View file

@ -1,4 +1,7 @@
use ray_tracing_core::{prelude::Rng, scene::Scene};
use ray_tracing_core::{
prelude::{Material, Rng},
scene::Scene,
};
use crate::shape::Shape;
@ -8,19 +11,25 @@ pub struct PbrtScene {
}
impl<R: Rng> Scene<R> for PbrtScene {
type Mat<'a>
= &'a dyn Material<R>
where
R: 'a;
fn intersect(
&self,
ray: ray_tracing_core::prelude::Ray,
min: ray_tracing_core::prelude::Float,
max: ray_tracing_core::prelude::Float,
) -> Option<ray_tracing_core::scene::Intersection<'_, R>> {
) -> Option<ray_tracing_core::scene::Intersection<R, Self::Mat<'_>>> {
let mut i = None;
for s in &self.shapes {
if let Some(new_i) = s.intersect::<R>(ray, min, max)
&& i.as_ref()
.is_none_or(|i: &ray_tracing_core::scene::Intersection<'_, R>| {
&& i.as_ref().is_none_or(
|i: &ray_tracing_core::scene::Intersection<'_, R, Self::Mat<'_>>| {
i.t() > new_i.t()
})
},
)
{
i = Some(new_i);
}
@ -29,12 +38,15 @@ impl<R: Rng> Scene<R> for PbrtScene {
i
}
fn sample_light(
fn sample_light<'b>(
&self,
w_in: ray_tracing_core::prelude::Dir3,
intersection: &ray_tracing_core::scene::Intersection<'_, R>,
intersection: &ray_tracing_core::scene::Intersection<'_, R, Self::Mat<'b>>,
rng: &mut R,
) -> Option<ray_tracing_core::scene::LightSample<'_, R>> {
) -> Option<ray_tracing_core::scene::LightSample<'_, R>>
where
Self: 'b,
{
None
}
}

View file

@ -161,7 +161,7 @@ impl Shape {
ray: Ray,
min: Float,
max: Float,
) -> Option<Intersection<R>> {
) -> Option<Intersection<R, &'_ dyn Material<R>>> {
let ray = self.ctm.transform_ray(ray);
match &self.obj {