54 lines
1.1 KiB
Rust
54 lines
1.1 KiB
Rust
use crate::prelude::*;
|
|
use rand::Rng;
|
|
|
|
/// All calculations for the material are done a tangent space of the intersection.
|
|
pub trait Material<R: Rng>: Sync {
|
|
fn eval(&self, w_in: Dir3, w_out: Dir3, rng: &mut R) -> Option<Color> {
|
|
None
|
|
}
|
|
|
|
fn emit(&self, w_in: Dir3, rng: &mut R) -> Option<Color> {
|
|
None
|
|
}
|
|
}
|
|
|
|
pub struct DefaultMaterial {}
|
|
|
|
impl<R: Rng> Material<R> for DefaultMaterial {
|
|
// evaluates the bsdf
|
|
fn eval(&self, _w_in: Dir3, _w_out: Dir3, _rng: &mut R) -> Option<Color> {
|
|
None
|
|
}
|
|
}
|
|
|
|
pub struct DiffuseMaterial {
|
|
color: Color,
|
|
}
|
|
|
|
impl DiffuseMaterial {
|
|
pub fn new(color: Color) -> Self {
|
|
Self { color }
|
|
}
|
|
}
|
|
|
|
impl<R: Rng> Material<R> for DiffuseMaterial {
|
|
fn eval(&self, _w_in: Dir3, _w_out: Dir3, _rng: &mut R) -> Option<Color> {
|
|
Some(self.color)
|
|
}
|
|
}
|
|
|
|
pub struct AreaLight {
|
|
color: Color,
|
|
}
|
|
|
|
impl AreaLight {
|
|
pub fn new(color: Color) -> Self {
|
|
Self { color }
|
|
}
|
|
}
|
|
|
|
impl<R: Rng> Material<R> for AreaLight {
|
|
fn emit(&self, _w_in: Dir3, _rng: &mut R) -> Option<Color> {
|
|
Some(self.color)
|
|
}
|
|
}
|