Add light as associated type for scene and get something to draw with pbrt materials.

This commit is contained in:
hal8174 2025-08-26 20:27:24 +02:00
parent b54a2b16fe
commit bb2089477e
Signed by: hal8174
SSH key fingerprint: SHA256:NN98ZYwnrreQLSOV/g+amY7C3yL/mS1heD7bi5t6PPw
13 changed files with 286 additions and 87 deletions

View file

@ -78,12 +78,19 @@ impl<A: AccelerationStructure<u32>, R: Rng> Scene<R> for AccelerationStructureSc
where
A: 'a,
R: 'a;
type Light<'b>
= &'b dyn Light<R>
where
A: 'b,
R: 'b;
fn intersect(
&self,
ray: Ray,
min: Float,
max: Float,
) -> Option<ray_tracing_core::scene::Intersection<'_, R, Self::Mat<'_>>> {
) -> Option<ray_tracing_core::scene::Intersection<R, Self::Mat<'_>, Self::Light<'_>>> {
let (t, n, i) = self.acceleration_structure.intersect(ray, min, max)?;
let material = &self.materials[i as usize];
@ -106,7 +113,7 @@ impl<A: AccelerationStructure<u32>, R: Rng> Scene<R> for AccelerationStructureSc
fn sample_light<'b>(
&self,
_w_in: Dir3,
_intersection: &ray_tracing_core::scene::Intersection<'_, R, Self::Mat<'b>>,
_intersection: &ray_tracing_core::scene::Intersection<R, Self::Mat<'b>, Self::Light<'b>>,
rng: &mut R,
) -> Option<ray_tracing_core::scene::LightSample<'_, R>>
where

View file

@ -37,13 +37,19 @@ where
M: 'a,
R: 'a;
type Light<'b>
= &'b dyn Light<R>
where
M: 'b,
R: 'b;
fn intersect(
&self,
ray: Ray,
min: Float,
max: Float,
) -> Option<Intersection<'_, R, Self::Mat<'_>>> {
let mut intersection: Option<Intersection<'_, R, Self::Mat<'_>>> = None;
) -> Option<Intersection<R, Self::Mat<'_>, Self::Light<'_>>> {
let mut intersection: Option<Intersection<R, Self::Mat<'_>, Self::Light<'_>>> = None;
for &(c, r) in &self.spheres {
let offset = ray.start() - c;
@ -84,7 +90,7 @@ where
fn sample_light<'b>(
&self,
_w_in: Dir3,
_intersection: &Intersection<'_, R, Self::Mat<'b>>,
_intersection: &Intersection<R, Self::Mat<'b>, Self::Light<'b>>,
_rng: &mut R,
) -> Option<ray_tracing_core::scene::LightSample<'_, R>>
where

View file

@ -323,12 +323,17 @@ impl<R: Rng> Scene<R> for TriangleBVH<R> {
where
R: 'a;
type Light<'b>
= &'b dyn Light<R>
where
R: 'b;
fn intersect(
&self,
ray: Ray,
min: Float,
max: Float,
) -> Option<ray_tracing_core::scene::Intersection<'_, R, Self::Mat<'_>>> {
) -> Option<ray_tracing_core::scene::Intersection<R, Self::Mat<'_>, Self::Light<'_>>> {
let (i, t) = self.intersect_bvh(0, ray, min, max)?;
let triangle = self.triangles[i as usize];
@ -350,7 +355,7 @@ impl<R: Rng> Scene<R> for TriangleBVH<R> {
fn sample_light<'b>(
&self,
_w_in: Dir3,
_intersection: &Intersection<'_, R, Self::Mat<'b>>,
_intersection: &Intersection<R, Self::Mat<'b>, Self::Light<'b>>,
rng: &mut R,
) -> Option<ray_tracing_core::scene::LightSample<'_, R>>
where