Change Scene trait to account for material data
This commit is contained in:
parent
76448ed442
commit
2bc5ec93fe
19 changed files with 306 additions and 124 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue