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(

View file

@ -28,7 +28,7 @@ pub fn example_scenes<R: Rng + Debug + 'static>() -> HashMap<&'static str, Box<d
"stanford_dragon_microfacet",
Box::new(stanford_dragon::StanfordDragon::new(material)),
);
let material = Iridescent::new(100.0, 900.0, 1.0, 1.5, 20);
let material = Iridescent::new(250.0, 250.0, 1.0, 1.5, 20);
map.insert(
"stanford_dragon_iridescent",
Box::new(stanford_dragon::StanfordDragon::new(material)),
@ -43,11 +43,15 @@ pub fn example_scenes<R: Rng + Debug + 'static>() -> HashMap<&'static str, Box<d
Box::new(stanford_dragon_as::StanfordDragon::new()),
);
map.insert("mis_test", Box::new(mis_test::MISTest::new()));
let material = Iridescent::new(250.0, 250.0, 1.0, 1.3, 20);
map.insert("sphere", Box::new(sphere::SphereScene::new(material)));
map
}
pub mod basic_cornell;
pub mod cornell2;
pub mod mis_test;
pub mod sphere;
pub mod stanford_dragon;
pub mod stanford_dragon_as;

View file

@ -0,0 +1,50 @@
use std::{
cell::{Cell, OnceCell},
marker::PhantomData,
};
use ray_tracing_core::prelude::*;
use crate::basic_scene::BasicScene;
use super::ExampleScene;
pub struct SphereScene<M> {
scene: OnceCell<BasicScene<M>>,
material: Cell<Option<M>>,
}
impl<M> SphereScene<M> {
pub fn new(material: M) -> Self {
Self {
scene: OnceCell::new(),
material: Cell::new(Some(material)),
}
}
}
impl<R: Rng + 'static, M: Material<R> + Clone + 'static> ExampleScene<R> for SphereScene<M> {
fn get_scene(&self) -> Box<dyn ray_tracing_core::scene::Scene<R> + Sync> {
let s = self
.scene
.get_or_init(|| BasicScene::new(self.material.take().unwrap()));
Box::new(s.clone())
}
fn get_camera_pos(&self) -> Pos3 {
Pos3::new(5.0, 1.0, 0.0)
}
fn get_camera_look_at(&self) -> Pos3 {
Pos3::new(0.0, 0.0, 0.0)
}
fn get_camera_up(&self) -> Dir3 {
Dir3::up()
}
fn get_horizontal_fov(&self) -> Float {
Float::to_radians(90.0)
}
}