1use crate::prelude::*;
4#[cfg(feature = "serde")]
5use serde::{de::DeserializeOwned, Deserialize, Serialize};
6
7#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
9#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10#[cfg_attr(feature = "serde", serde(bound = "T: Serialize + DeserializeOwned"))]
11pub enum LightSource<T = f64, const N: usize = 3> {
12 Ambient,
14 Point(Point<T, N>),
16 Direction(Vector<T, N>),
18}
19
20#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
22#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
23#[cfg_attr(feature = "serde", serde(bound = "T: Serialize + DeserializeOwned"))]
24pub struct Light<T = f64, const N: usize = 3> {
25 pub source: LightSource<T, N>,
27 pub intensity: T,
29}
30
31impl<T, const N: usize> Light<T, N> {
32 pub const fn new(source: LightSource<T, N>, intensity: T) -> Self {
34 Self { source, intensity }
35 }
36
37 pub const fn ambient(intensity: T) -> Self {
39 Self::new(LightSource::Ambient, intensity)
40 }
41
42 pub fn point<P>(intensity: T, position: P) -> Self
44 where
45 P: Into<Point<T, N>>,
46 {
47 Self::new(LightSource::Point(position.into()), intensity)
48 }
49
50 pub fn direction<V>(intensity: T, direction: V) -> Self
52 where
53 V: Into<Vector<T, N>>,
54 {
55 Self::new(LightSource::Direction(direction.into()), intensity)
56 }
57}
58
59impl<T, const N: usize> Default for Light<T, N>
60where
61 T: Default,
62{
63 fn default() -> Self {
64 Self::new(LightSource::Ambient, T::default())
65 }
66}