Document Material trait

This commit is contained in:
hal8174 2025-01-09 22:58:47 +01:00
parent 908efa79c2
commit ed7b0454d0

View file

@ -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<R: Rng>: 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,