summaryrefslogtreecommitdiffhomepage
path: root/main
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-06-17 09:54:12 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-06-17 10:02:17 +0200
commit6c33746542f91abc300319cd057839299d17dea5 (patch)
treea1109100959c500e812d58905d8abc5882d94320 /main
parent0c9383d5944a53b9b6fcc60fc56450a5418f0963 (diff)
wip
Diffstat (limited to 'main')
-rw-r--r--main/draw.cpp51
-rw-r--r--main/main-impl.hpp4
2 files changed, 40 insertions, 15 deletions
diff --git a/main/draw.cpp b/main/draw.cpp
index 4628eaf8..67e92e91 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -4,6 +4,7 @@
#include "src/camera-offset.hpp"
#include "src/anim-atlas.hpp"
#include "main/clickable.hpp"
+#include "src/light.hpp"
#include <Corrade/Containers/ArrayView.h>
#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/GL/Renderer.h>
@@ -114,27 +115,48 @@ auto main_impl::get_draw_bounds() const noexcept -> draw_bounds
return {x0, x1, y0, y1};
}
-void main_impl::draw_lights_for_chunk(chunk& c, chunk_coords_ ch, Vector2b neighbor_offset) noexcept
+bool main_impl::draw_lights_for_chunk(chunk& c, Vector2b neighbor_offset) noexcept
{
+ bool ret = false;
for (const auto& e_ : c.entities())
{
const auto& e = *e_;
if (e.type_of() != entity_type::light)
continue;
- // todo
+ const auto& li = static_cast<const light&>(e);
+ if (li.max_distance >= 1e-4f || li.falloff == light_falloff::constant)
+ {
+ ret = true;
+ auto L = light_s {
+ .center = Vector2(li.coord.local()) * TILE_SIZE2 + Vector2(li.offset),
+ .dist = li.max_distance,
+ .color = li.color,
+ .falloff = li.falloff,
+ };
+ _lightmap_shader.begin_light(neighbor_offset, L);
+ _lightmap_shader.add_chunk(neighbor_offset, c);
+ _lightmap_shader.finish_and_blend_light();
+ }
}
+ return ret;
}
-void main_impl::draw_lights(chunk& c, chunk_coords_ ch, const std::array<chunk*, 8>& ns) noexcept
+bool main_impl::draw_lights(chunk& c, const std::array<chunk*, 8>& ns) noexcept
{
+ bool ret = false;
+ _lightmap_shader.bind();
+ _lightmap_shader.begin_accum();
+
for (auto i = 0uz; i < 8; i++)
if (ns[i] != nullptr)
{
auto off = world::neighbor_offsets[i];
- draw_lights_for_chunk(*ns[i], ch + off, off);
+ ret |= draw_lights_for_chunk(*ns[i], off);
}
+ ret |= draw_lights_for_chunk(c, {});
- draw_lights_for_chunk(c, ch, {});
+ _lightmap_shader.end_accum();
+ return ret;
}
void main_impl::draw_world() noexcept
@@ -166,16 +188,19 @@ void main_impl::draw_world() noexcept
auto* c_ = _world.at(ch);
if (!c_)
continue;
- std::array<chunk*, 8> ns = {};
- for (auto i = 0uz; i < 8; i++)
+ auto& c = *c_;
{
- auto off = world::neighbor_offsets[i];
- auto n = chunk_coords_{int16_t(x + off.x()), int16_t(y + off.y()), z};
- ns[i] = _world.at(n);
+ std::array<chunk*, 8> ns = {};
+ for (auto i = 0uz; i < 8; i++)
+ {
+ auto off = world::neighbor_offsets[i];
+ auto n = chunk_coords_{int16_t(x + off.x()), int16_t(y + off.y()), z};
+ ns[i] = _world.at(n);
+ }
+ draw_lights(c, ns);
}
- auto& c = *c_;
- //draw_lights(c, ch, ns);
- // tex = _lightmap_shader.texture(); // todo
+ bind();
+
const with_shifted_camera_offset o{_shader, ch, {minx, miny}, {maxx, maxy}};
if (check_chunk_visible(_shader.camera_offset(), sz))
{
diff --git a/main/main-impl.hpp b/main/main-impl.hpp
index 19edce8b..a6457524 100644
--- a/main/main-impl.hpp
+++ b/main/main-impl.hpp
@@ -121,8 +121,8 @@ private:
void recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept;
void draw_world() noexcept;
- void draw_lights(chunk& c, chunk_coords_ ch, const std::array<chunk*, 8>& neighbors) noexcept;
- void draw_lights_for_chunk(chunk& c, chunk_coords_ ch, Vector2b neighbor_offset) noexcept;
+ bool draw_lights(chunk& c, const std::array<chunk*, 8>& neighbors) noexcept;
+ bool draw_lights_for_chunk(chunk& c, Vector2b neighbor_offset) noexcept;
draw_bounds get_draw_bounds() const noexcept override;