summaryrefslogtreecommitdiffhomepage
path: root/src/light.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-05-17 17:06:16 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-05-17 17:08:52 +0200
commit8138cc9a269844b6c0a84c193a7a43aec7010592 (patch)
tree1d7c1f1b37c7f714fd0976bfa839e0b18ca2385d /src/light.cpp
parent08b89c6575947e8fdcba9b6c329c25aa8472e52b (diff)
wip vobj
Diffstat (limited to 'src/light.cpp')
-rw-r--r--src/light.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/light.cpp b/src/light.cpp
new file mode 100644
index 00000000..64da857b
--- /dev/null
+++ b/src/light.cpp
@@ -0,0 +1,42 @@
+#include "light.hpp"
+#include "shaders/shader.hpp"
+#include <cmath>
+
+namespace floormat {
+
+light_proto::light_proto() = default;
+light_proto::light_proto(const light_proto&) = default;
+light_proto& light_proto::operator=(const light_proto&) = default;
+light_proto::~light_proto() noexcept = default;
+bool light_proto::operator==(const light_proto&) const = default;
+
+light::light(object_id id, struct chunk& c, const light_proto& proto) :
+ entity{id, c, proto},
+ half_dist{proto.half_dist},
+ color{proto.color},
+ falloff{proto.falloff}
+{
+}
+
+float light::depth_offset() const
+{
+ constexpr auto ret = 4.f / tile_shader::depth_tile_size;
+ return ret;
+}
+
+Vector2 light::ordinal_offset(Vector2b) const { return {}; }
+entity_type light::type() const noexcept { return entity_type::light; }
+bool light::update(size_t, float) { return false; }
+bool light::is_virtual() const { return true; }
+
+float light::calc_intensity(float 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;
+ }
+}
+
+} // namespace floormat