diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-05-17 17:06:16 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-05-17 17:08:52 +0200 |
commit | 8138cc9a269844b6c0a84c193a7a43aec7010592 (patch) | |
tree | 1d7c1f1b37c7f714fd0976bfa839e0b18ca2385d /src | |
parent | 08b89c6575947e8fdcba9b6c329c25aa8472e52b (diff) |
wip vobj
Diffstat (limited to 'src')
-rw-r--r-- | src/chunk-scenery.cpp | 5 | ||||
-rw-r--r-- | src/light-falloff.hpp | 9 | ||||
-rw-r--r-- | src/light.cpp | 42 | ||||
-rw-r--r-- | src/light.hpp | 44 |
4 files changed, 96 insertions, 4 deletions
diff --git a/src/chunk-scenery.cpp b/src/chunk-scenery.cpp index edfbfeb1..a2a61907 100644 --- a/src/chunk-scenery.cpp +++ b/src/chunk-scenery.cpp @@ -150,9 +150,8 @@ auto chunk::ensure_scenery_mesh(scenery_scratch_buffers buffers) noexcept -> sce { if (e->is_dynamic()) continue; - if (e->is_virtual()) - continue; const auto& atlas = e->atlas; + fm_debug_assert(atlas != nullptr); const auto& fr = *e; const auto pos = e->coord.local(); const auto coord = Vector3(pos) * TILE_SIZE + Vector3(Vector2(fr.offset), 0); @@ -182,8 +181,6 @@ auto chunk::ensure_scenery_mesh(scenery_scratch_buffers buffers) noexcept -> sce uint32_t j = 0, i = 0; for (const auto& e : _entities) { - if (e->is_virtual()) - continue; auto index = e->is_dynamic() ? (uint32_t)-1 : j++; array[i++] = { e.get(), (uint32_t)-1, e->ordinal(), make_topo_sort_data(*e, index) }; } diff --git a/src/light-falloff.hpp b/src/light-falloff.hpp new file mode 100644 index 00000000..e90d11aa --- /dev/null +++ b/src/light-falloff.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace floormat { + +enum class light_falloff : uint8_t { + linear, quadratic, constant, +}; + +} // namespace floormat 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 diff --git a/src/light.hpp b/src/light.hpp new file mode 100644 index 00000000..73d28272 --- /dev/null +++ b/src/light.hpp @@ -0,0 +1,44 @@ +#pragma once +#include "src/light-falloff.hpp" +#include "src/entity.hpp" +#include <Magnum/Magnum.h> +#include <Magnum/Math/Vector2.h> +#include <Magnum/Math/Color.h> + +namespace floormat { + +struct light_proto : entity_proto +{ + light_proto(); + light_proto(const light_proto&); + light_proto& operator=(const light_proto&); + ~light_proto() noexcept override; + bool operator==(const light_proto&) const; + + Vector2 half_dist{3}; + Color3ub color{255, 255, 255}; + light_falloff falloff : 3 = light_falloff::linear; + uint8_t symmetric : 1 = true; +}; + +struct light final : entity +{ + Vector2 half_dist; + Color3ub color; + light_falloff falloff : 3; + uint8_t symmetric : 1 = true; + + light(object_id id, struct chunk& c, const light_proto& proto); + + Vector2 ordinal_offset(Vector2b offset) const override; + float depth_offset() const override; + entity_type type() const noexcept override; + bool update(size_t i, float dt) override; + bool is_virtual() const override; + + static float calc_intensity(float half_dist, light_falloff falloff); + + friend struct world; +}; + +} // namespace floormat |