25 lines
463 B
Rust
25 lines
463 B
Rust
use crate::prelude::*;
|
|
|
|
pub trait Light<R: Rng>: Sync {
|
|
fn emit(&self, w_in: Dir3, rng: &mut R) -> Color;
|
|
}
|
|
|
|
pub struct AreaLight {
|
|
pub(crate) color: Color,
|
|
}
|
|
|
|
impl AreaLight {
|
|
pub fn new(color: Color) -> Self {
|
|
Self { color }
|
|
}
|
|
}
|
|
|
|
impl<R: Rng> Light<R> for AreaLight {
|
|
fn emit(&self, w_in: Dir3, _rng: &mut R) -> Color {
|
|
if w_in.y() > 0.0 {
|
|
self.color
|
|
} else {
|
|
Color::black()
|
|
}
|
|
}
|
|
}
|