Fix color matching function
This commit is contained in:
parent
e3009563ba
commit
543bf7e1bf
6 changed files with 241 additions and 73 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue