diff --git a/ray-tracing-core/src/material.rs b/ray-tracing-core/src/material.rs index e836016..79eae71 100644 --- a/ray-tracing-core/src/material.rs +++ b/ray-tracing-core/src/material.rs @@ -1,16 +1,26 @@ use crate::prelude::*; use std::fmt::Debug; +/// Trait to model bxdf. +/// +/// f(w_in, w_out) * cos(theta) / pdf +/// /// All calculations for the material are done a tangent space of the intersection. +/// +/// The sample function has to sample according to the pdf function pub trait Material: Send + Sync + Debug { + /// evaluate f(w_in, w_out) fn eval(&self, w_in: Dir3, w_out: Dir3, rng: &mut R) -> Color; + /// sample w_out and return: + /// f(w_in, w_out) * cos(theta) / pdf fn sample(&self, w_in: Dir3, rng: &mut R) -> SampleResult { let w_out = Dir3::sample_cosine_hemisphere(rng); SampleResult::new(w_out, self.eval(w_in, w_out, rng) * FloatConsts::PI, false) } + /// returns the pdf for (w_in, w_out) fn pdf(&self, w_in: Dir3, w_out: Dir3) -> Float { let _ = w_out; FloatConsts::FRAC_1_PI * Float::max(w_in.y(), 0.0) @@ -25,6 +35,7 @@ pub struct SampleResult { } impl SampleResult { + /// In case the sample is according to a delta distribution the delta flat has to be set. pub fn new(w_out: Dir3, color: Color, delta: bool) -> Self { Self { w_out,