diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-05-26 15:48:45 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-05-26 15:48:45 +0200 |
commit | 0e3c3cb0ebdb641f71d356aab98b8f2aca675d2a (patch) | |
tree | e2cdde63c31d171f4f5f3cc918a52657b4d37815 | |
parent | 7d421d0069dbc8bcf948a29d39c3f8e65de19b33 (diff) |
light: intensity should be a 2d vector
It's a vector in order to provide an approximation of area lighting
without actually implementing them.
-rw-r--r-- | src/light.cpp | 11 | ||||
-rw-r--r-- | src/light.hpp | 3 |
2 files changed, 10 insertions, 4 deletions
diff --git a/src/light.cpp b/src/light.cpp index ed7c4ae1..ed9469f2 100644 --- a/src/light.cpp +++ b/src/light.cpp @@ -43,14 +43,19 @@ bool light::update(size_t, float) { return false; } bool light::is_dynamic() const { return true; } bool light::is_virtual() const { return true; } -float light::calc_intensity(float half_dist, light_falloff falloff) +Vector2 light::intensity(Vector2 half_dist, light_falloff falloff) { switch (falloff) { case light_falloff::linear: return 2 * half_dist; - case light_falloff::quadratic: return std::sqrt(2 * half_dist); - default: case light_falloff::constant: return 1; + case light_falloff::quadratic: return Vector2{std::sqrt(2 * half_dist.x()), std::sqrt(2 * half_dist.y())}; + default: case light_falloff::constant: return Vector2{1, 1}; } } +Vector2 light::intensity() const +{ + return intensity(half_dist, falloff); +} + } // namespace floormat diff --git a/src/light.hpp b/src/light.hpp index 15dbc7c6..e228c8b5 100644 --- a/src/light.hpp +++ b/src/light.hpp @@ -37,7 +37,8 @@ struct light final : entity bool is_dynamic() const override; bool is_virtual() const override; - static float calc_intensity(float half_dist, light_falloff falloff); + static Vector2 intensity(Vector2 half_dist, light_falloff falloff); + Vector2 intensity() const; friend struct world; }; |