summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/imgui.cpp2
-rw-r--r--shaders/lightmap.cpp14
-rw-r--r--shaders/lightmap.hpp17
3 files changed, 20 insertions, 13 deletions
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index e49b9120..fbf7ab83 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -252,7 +252,7 @@ void app::draw_lightmap_test()
//constexpr auto img_size = 1 / Vector2(lightmap_shader::max_chunks);
if (ImGui::Begin("Lightmap", &is_open, flags))
{
- ImGui::Image(&shader.scratch_texture(), preview_size, {0, 0}, {1, 1});
+ ImGui::Image(&shader.accum_texture(), preview_size, {0, 0}, {1, 1});
ImGui::End();
}
if (!is_open)
diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp
index 6b09c5f8..10d8fd9e 100644
--- a/shaders/lightmap.cpp
+++ b/shaders/lightmap.cpp
@@ -27,7 +27,8 @@ namespace floormat {
namespace {
-constexpr auto neighbor_count = 8;
+constexpr auto neighbor_count = lightmap_shader::neighbor_count;
+
constexpr auto chunk_size = TILE_SIZE2 * TILE_MAX_DIM;
constexpr auto chunk_offset = TILE_SIZE2/2;
constexpr auto image_size = iTILE_SIZE2 * TILE_MAX_DIM * neighbor_count;
@@ -75,7 +76,7 @@ auto lightmap_shader::make_framebuffer(Vector2i size) -> Framebuffer
.attachTexture(GL::Framebuffer::ColorAttachment{1}, framebuffer.accum, 0)
//.clearDepth(0);
.clearColor(0, Color4{1, 0, 1, 1})
- .clearColor(1, Color4{0, 0, 0, 1});
+ .clearColor(1, Color4{0, 1, 0, 1});
//framebuffer.fb.mapForDraw(GL::Framebuffer::ColorAttachment{0});
using BF = Magnum::GL::Renderer::BlendFunction;
@@ -117,6 +118,8 @@ void lightmap_shader::end_occlusion()
vertex_buf.setSubData(0, vertexes.prefix(count));
index_buf.setSubData(0, indexes.prefix(count));
}
+
+ framebuffer.fb.clearColor(1, Color4{0, 0, 1, 1});
}
std::array<Vector3, 4>& lightmap_shader::alloc_rect()
@@ -212,6 +215,8 @@ std::array<UnsignedShort, 6> lightmap_shader::quad_indexes(size_t N)
void lightmap_shader::add_light(Vector2 neighbor_offset, const light_s& light)
{
+ neighbor_offset += half_neighbors;
+
constexpr auto tile_size = TILE_SIZE2.sum()/2;
float I;
@@ -236,11 +241,10 @@ void lightmap_shader::add_light(Vector2 neighbor_offset, const light_s& light)
float alpha = light.color.a() / 255.f;
auto color = (Vector3{light.color.rgb()} / 255.f) * alpha;
- framebuffer.fb.mapForDraw(GL::Framebuffer::ColorAttachment{0});
framebuffer.fb.clearColor(0, Color4{0, 0, 0, 1});
setUniform(LightColorUniform, color * alpha);
- setUniform(SizeUniform, 1 / chunk_size);
+ setUniform(SizeUniform, 1 / (chunk_size * neighbor_count));
setUniform(CenterFragcoordUniform, center_fragcoord);
setUniform(CenterClipUniform, center_clip);
setUniform(RangeUniform, I);
@@ -323,6 +327,8 @@ void lightmap_shader::add_rect(Vector2 neighbor_offset, Pair<Vector2, Vector2> m
void lightmap_shader::add_chunk(Vector2 neighbor_offset, chunk& c)
{
+ neighbor_offset += half_neighbors;
+
add_geometry(neighbor_offset, c);
add_entities(neighbor_offset, c);
}
diff --git a/shaders/lightmap.hpp b/shaders/lightmap.hpp
index 76ef081a..22748d16 100644
--- a/shaders/lightmap.hpp
+++ b/shaders/lightmap.hpp
@@ -43,17 +43,15 @@ struct lightmap_shader final : GL::AbstractShaderProgram
void begin_occlusion();
void end_occlusion();
void add_chunk(Vector2 neighbor_offset, chunk& c);
- void add_entities(Vector2 neighbor_offset, chunk& c);
- void add_geometry(Vector2 neighbor_offset, chunk& c);
- void add_rect(Vector2 neighbor_offset, Vector2 min, Vector2 max);
- void add_rect(Vector2 neighbor_offset, Pair<Vector2, Vector2> minmax);
void add_light(Vector2 neighbor_offset, const light_s& light);
void bind();
GL::Texture2D& scratch_texture();
GL::Texture2D& accum_texture();
- static constexpr auto max_chunks = Vector2s(8, 8);
+ // todo allow 16 neighbors on new gpu's
+ static constexpr auto neighbor_count = 8;
+ static constexpr auto half_neighbors = Vector2(neighbor_count)/2;
using Position = GL::Attribute<0, Vector3>;
@@ -84,7 +82,12 @@ private:
GL::Mesh make_occlusion_mesh();
static std::array<UnsignedShort, 6> quad_indexes(size_t N);
- // todo use setData() and a boolean flag on capacity change
+ void add_entities(Vector2 neighbor_offset, chunk& c);
+ void add_geometry(Vector2 neighbor_offset, chunk& c);
+ void add_rect(Vector2 neighbor_offset, Vector2 min, Vector2 max);
+ void add_rect(Vector2 neighbor_offset, Pair<Vector2, Vector2> minmax);
+ [[nodiscard]] std::array<Vector3, 4>& alloc_rect();
+
GL::Buffer vertex_buf{NoCreate}, index_buf{NoCreate};
Array<std::array<Vector3, 4>> vertexes; // todo make a contiguous allocation
Array<std::array<UnsignedShort, 6>> indexes;
@@ -96,8 +99,6 @@ private:
std::array<Vector3, 4> light_vertexes;
GL::Buffer light_vertex_buf{NoCreate};
GL::Mesh light_mesh{NoCreate};
-
- [[nodiscard]] std::array<Vector3, 4>& alloc_rect();
};
} // namespace floormat