summaryrefslogtreecommitdiffstats
path: root/engine/src/render/light.rs
blob: 85c91d763cb3e65b99dd3eab37ee66bf915ac723 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2020 Sergiusz 'q3k' Bazanski <q3k@q3k.org>
//
// This file is part of Abrasion.
//
// Abrasion is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 3.
//
// Abrasion is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// Abrasion.  If not, see <https://www.gnu.org/licenses/>.

use std::time;

use cgmath as cgm;

use crate::physics::color;
use crate::render::vulkan::data;

/// An Omni point light, with position in 3d space, and 'color' defined in lumens per CIE XYZ
/// color channel.
#[derive(Debug)]
pub struct Omni {
    /// Luminour power/flux defined as lumens per XYZ color channel.
    pub color: color::XYZ,
}


impl Omni {
    /// Make a test light. This has... a color. It's kinda yellow. And something close to 650
    /// lumens of luminous power. 
    // TODO(q3k): implement [Kry85] (eq. 68) somewhere in //engine/src/physics for generation
    // of nice lights colours from color temperature.
    //
    // [Kry85]
    // M. Krystek. 1985. "An algorithm to calculate correlated color temperature"
    // Color Research & Application, 10 (1), 38–40.
    pub fn test() -> Self {
        Self::with_color(color::XYZ::new(234.7*100.0, 214.1*100.0, 207.9*100.0))
    }

    pub fn with_color(color: color::XYZ) -> Self{
        Self {
            color,
        }
    }

    pub fn vulkan_uniform(&self, pos: &cgm::Vector4<f32>) -> data::OmniLight {
        // TODO: cache this?
        data::OmniLight {
            pos: [pos.x, pos.y, pos.z, pos.w],
            color: [self.color.x, self.color.y, self.color.z, 0.0],
        }
    }
}

#[derive(Debug)]
pub enum Light {
    Omni(Omni),
}

impl Light {
    pub fn omni_test() -> Light {
        Light::Omni(Omni::test())
    }
    pub fn omni_with_color(color: color::XYZ) -> Light {
        Light::Omni(Omni::with_color(color))
    }
}