Fix color matching function

This commit is contained in:
hal8174 2025-05-25 19:55:38 +02:00
parent e3009563ba
commit 543bf7e1bf
Signed by: hal8174
SSH key fingerprint: SHA256:JwuqS+eVfISfKr+DkDQ6NWAbGd1jFAHkPpCM1yCnlTs
6 changed files with 241 additions and 73 deletions

View file

@ -1,26 +1,32 @@
use ray_tracing_core::light::AreaLight;
use ray_tracing_core::prelude::*;
use ray_tracing_core::scene::{Intersection, Scene};
use ray_tracing_material::default::DefaultMaterial;
pub struct BasicScene {
#[derive(Clone)]
pub struct BasicScene<M> {
pub(crate) spheres: Vec<(Pos3, Float)>,
area_light: AreaLight,
material: M,
}
impl BasicScene {
pub fn new() -> Self {
impl<M> BasicScene<M> {
pub fn new(material: M) -> Self {
Self {
spheres: vec![(Pos3::zero(), 1.0), (Pos3::new(0.0, 0.0, 2.5), 2.0)],
spheres: vec![(Pos3::zero(), 1.0), (Pos3::new(0.0, -4.5, 0.0), 4.0)],
area_light: AreaLight::new(Color::white()),
material,
}
}
}
impl Default for BasicScene {
impl Default for BasicScene<DefaultMaterial> {
fn default() -> Self {
Self::new()
Self::new(DefaultMaterial {})
}
}
impl<R: Rng> Scene<R> for BasicScene {
impl<R: Rng, M: Material<R>> Scene<R> for BasicScene<M> {
fn intersect(&self, ray: Ray, min: Float, max: Float) -> Option<Intersection<'_, R>> {
let mut intersection: Option<Intersection<'_, R>> = None;
@ -35,7 +41,7 @@ impl<R: Rng> Scene<R> for BasicScene {
let int = Intersection::new(
d,
((ray.start() + d * ray.dir()) - c).normalize(),
Some(&DefaultMaterial {}),
Some(&self.material),
None,
0.0,
);
@ -51,7 +57,13 @@ impl<R: Rng> Scene<R> for BasicScene {
}
}
intersection
Some(intersection.unwrap_or(Intersection::new(
Float::INFINITY,
-ray.dir(),
None,
Some(&self.area_light),
0.0,
)))
}
fn sample_light(