summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--editor/imgui.cpp54
-rw-r--r--external/CMakeLists.txt2
-rw-r--r--main/draw.cpp4
-rw-r--r--shaders/lightmap.cpp32
-rw-r--r--shaders/lightmap.frag25
-rw-r--r--shaders/lightmap.hpp18
-rw-r--r--shaders/lightmap.vert16
8 files changed, 95 insertions, 58 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a1c0f28d..d363e32a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -171,6 +171,8 @@ endif()
if(MSVC)
add_compile_options(-GR-)
+else()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
endif()
fm_run_hook(fm-userconfig-src)
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index fbf7ab83..3a4d0245 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -217,20 +217,54 @@ void app::do_lightmap_test()
{
auto& e = *e_;
fm_assert(e_->type() == entity_type::light);
- const auto& li = static_cast<const light&>(e);
- light_s L {
- .center = Vector2(li.coord.local()) * TILE_SIZE2 + Vector2(li.offset),
- .dist = li.max_distance,
- .color = li.color,
- .falloff = li.falloff,
- };
auto& shader = M->lightmap_shader();
- auto ch = Vector2(e.coord.chunk());
+ auto ch = e.coord.chunk();
+ auto z = e.coord.z();
+ constexpr auto ns = lightmap_shader::neighbor_count;
+
shader.begin_occlusion();
- shader.add_chunk(ch, e.chunk()); // todo add neighbors
+
+#if 1
+ for (int j = ch.y - ns; j < ch.y + ns; j++)
+ for (int i = ch.x - ns; i < ch.x + ns; i++)
+ {
+ auto c = chunk_coords_{(int16_t)i, (int16_t)j, z};
+ if (auto* chunk = w.at(c))
+ {
+ auto offset = Vector2(Vector2i(c.x) - Vector2i(ch));
+ shader.add_chunk(offset, *chunk);
+ }
+ }
+#endif
+
shader.end_occlusion();
shader.bind();
- shader.add_light(ch, L);
+
+ for (int j = ch.y - ns; j < ch.y + ns; j++)
+ for (int i = ch.x - ns; i < ch.x + ns; i++)
+ {
+ auto c = chunk_coords_{(int16_t)i, (int16_t)j, z};
+ if (auto* chunk = w.at(c))
+ {
+ auto offset = Vector2(Vector2i(c.x) - Vector2i(ch));
+ for (const auto& e_ : chunk->entities())
+ {
+ if (e_->type() == entity_type::light)
+ {
+ const auto& li = static_cast<const light&>(*e_);
+ light_s L {
+ .center = Vector2(li.coord.local()) * TILE_SIZE2 + Vector2(li.offset),
+ .dist = li.max_distance,
+ .color = li.color,
+ .falloff = li.falloff,
+ };
+ shader.add_light(offset, L);
+ }
+ }
+ }
+ }
+
+ shader.finish();
M->bind();
}
}
diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt
index 27d69a88..578a05d0 100644
--- a/external/CMakeLists.txt
+++ b/external/CMakeLists.txt
@@ -258,6 +258,8 @@ if(FLOORMAT_SUBMODULE-DEPENDENCIES)
#fm_add_luajit()
if(MSVC)
add_compile_options(-GR-)
+ else()
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
endif()
add_subdirectory(fmt ${system})
add_subdirectory(json ${system})
diff --git a/main/draw.cpp b/main/draw.cpp
index 7dacc870..d74d9f38 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -50,12 +50,12 @@ void main_impl::recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept
// -- state ---
glEnable(GL_LINE_SMOOTH);
using BlendEquation = GL::Renderer::BlendEquation;
- using BF = GL::Renderer::BlendFunction;
+ using BlendFunction = GL::Renderer::BlendFunction;
using DepthFunction = GL::Renderer::DepthFunction;
using ProvokingVertex = GL::Renderer::ProvokingVertex;
using Feature = GL::Renderer::Feature;
GL::Renderer::setBlendEquation(BlendEquation::Add, BlendEquation::Add);
- GL::Renderer::setBlendFunction(BF::SourceAlpha, BF::OneMinusSourceAlpha);
+ GL::Renderer::setBlendFunction(BlendFunction::SourceAlpha, BlendFunction::OneMinusSourceAlpha);
GL::Renderer::disable(Feature::FaceCulling);
GL::Renderer::disable(Feature::DepthTest);
GL::Renderer::enable(Feature::Blending);
diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp
index 5a93721d..7fb3f198 100644
--- a/shaders/lightmap.cpp
+++ b/shaders/lightmap.cpp
@@ -10,14 +10,12 @@
#include <Corrade/Containers/PairStl.h>
#include <Corrade/Containers/Iterable.h>
#include <Corrade/Containers/ArrayViewStl.h>
-#include <Magnum/Magnum.h>
#include <Magnum/GL/Context.h>
#include <Magnum/GL/MeshView.h>
#include <Magnum/GL/Shader.h>
#include <Magnum/GL/Version.h>
#include <Magnum/GL/Renderer.h>
#include <Magnum/GL/TextureFormat.h>
-#include <Magnum/DebugTools/Screenshot.h>
#if defined __CLION_IDE__ || defined __clang__
#pragma GCC diagnostic ignored "-Wfloat-equal"
@@ -76,12 +74,12 @@ 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, 1, 0, 1});
- //framebuffer.fb.mapForDraw(GL::Framebuffer::ColorAttachment{0});
+ .clearColor(1, Color4{0, 0, 0, 1});
- using BF = Magnum::GL::Renderer::BlendFunction;
- GL::Renderer::setBlendFunction(0, BF::One, BF::Zero, BF::One, BF::Zero);
- GL::Renderer::setBlendFunction(1, BF::One, BF::One, BF::One, BF::One);
+ framebuffer.fb.mapForDraw({
+ { 0u, GL::Framebuffer::ColorAttachment{0} },
+ { 1u, GL::Framebuffer::ColorAttachment{1} },
+ });
return framebuffer;
}
@@ -118,8 +116,6 @@ 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()
@@ -259,11 +255,13 @@ void lightmap_shader::add_light(Vector2 neighbor_offset, const light_s& light)
{ -size.x() + center_clip.x(), size.y() + center_clip.y(), 0 },
}};
light_vertex_buf.setSubData(0, light_vertexes);
+
AbstractShaderProgram::draw(light_mesh);
setUniform(ModeUniform, DrawShadowsMode);
setUniform(LightColorUniform, Color3{0, 0, 0});
setUniform(RangeUniform, I);
+
fm_assert(occlusion_mesh.id());
auto mesh_view = GL::MeshView{occlusion_mesh};
mesh_view.setCount((int32_t)count*6);
@@ -271,10 +269,7 @@ void lightmap_shader::add_light(Vector2 neighbor_offset, const light_s& light)
AbstractShaderProgram::draw(mesh_view);
setUniform(ModeUniform, BlendLightmapMode);
- framebuffer.fb.mapForDraw(GL::Framebuffer::ColorAttachment{1});
AbstractShaderProgram::draw(light_mesh);
-
- //DebugTools::screenshot(framebuffer.fb, "../../../screenshot.bmp");
}
void lightmap_shader::add_rect(Vector2 neighbor_offset, Vector2 min, Vector2 max)
@@ -380,15 +375,18 @@ void lightmap_shader::add_entities(Vector2 neighbor_offset, chunk& c)
void lightmap_shader::bind()
{
- framebuffer.fb.mapForDraw(GL::Framebuffer::ColorAttachment{0});
framebuffer.fb.bind();
- GL::Renderer::setScissor({{}, {(int)1e6, (int)1e6}});
+ GL::Renderer::setScissor({{}, image_size});
+ framebuffer.fb.clearColor(1, Color4{0, 0, 0, 1});
+ using BlendFunction = Magnum::GL::Renderer::BlendFunction;
+ GL::Renderer::setBlendFunction(0, BlendFunction::One, BlendFunction::Zero);
+ GL::Renderer::setBlendFunction(1, BlendFunction::One, BlendFunction::One);
}
-GL::Texture2D& lightmap_shader::scratch_texture()
+void lightmap_shader::finish() // NOLINT(*-convert-member-functions-to-static)
{
- fm_debug_assert(framebuffer.scratch.id());
- return framebuffer.scratch;
+ using BlendFunction = Magnum::GL::Renderer::BlendFunction;
+ GL::Renderer::setBlendFunction(BlendFunction::SourceAlpha, BlendFunction::OneMinusSourceAlpha);
}
GL::Texture2D& lightmap_shader::accum_texture()
diff --git a/shaders/lightmap.frag b/shaders/lightmap.frag
index 91467907..deaaa894 100644
--- a/shaders/lightmap.frag
+++ b/shaders/lightmap.frag
@@ -1,15 +1,16 @@
precision mediump float;
-layout (location = 0) uniform sampler2D sampler;
-layout (location = 1) uniform vec3 light_color;
-layout (location = 2) uniform vec2 size;
-layout (location = 3) uniform vec2 center_fragcoord;
-layout (location = 4) uniform vec2 center_clip;
-layout (location = 5) uniform float range;
-layout (location = 6) uniform uint mode;
-layout (location = 7) uniform uint falloff;
+layout (location = 2) uniform sampler2D sampler0;
+layout (location = 3) uniform vec3 light_color;
+layout (location = 4) uniform vec2 size;
+layout (location = 5) uniform vec2 center_fragcoord;
+layout (location = 6) uniform vec2 center_clip;
+layout (location = 7) uniform float range;
+layout (location = 8) uniform uint mode;
+layout (location = 9) uniform uint falloff;
-out vec4 color;
+layout (location = 0) out vec4 color0;
+layout (location = 1) out vec4 color1;
//layout(origin_upper_left, pixel_center_integer) in vec4 gl_FragCoord;
@@ -27,14 +28,14 @@ void main() {
float tmp = max(0, L - dist);
A = tmp*tmp / (L*L);
}
- color = vec4(light_color.rgb, A);
+ color0 = vec4(light_color.rgb * A, 1);
}
else if (mode == 2) // blend
{
- color = texture(sampler, gl_FragCoord.xy * size);
+ color1 = texture(sampler0, gl_FragCoord.xy * size);
}
else if (mode == 0) // shadows
{
- color = vec4(0, 0, 0, 1);
+ color0 = vec4(0, 0, 0, 1);
}
}
diff --git a/shaders/lightmap.hpp b/shaders/lightmap.hpp
index 22748d16..22a94af0 100644
--- a/shaders/lightmap.hpp
+++ b/shaders/lightmap.hpp
@@ -45,8 +45,8 @@ struct lightmap_shader final : GL::AbstractShaderProgram
void add_chunk(Vector2 neighbor_offset, chunk& c);
void add_light(Vector2 neighbor_offset, const light_s& light);
void bind();
+ void finish();
- GL::Texture2D& scratch_texture();
GL::Texture2D& accum_texture();
// todo allow 16 neighbors on new gpu's
@@ -57,14 +57,14 @@ struct lightmap_shader final : GL::AbstractShaderProgram
private:
enum : Int {
- SamplerUniform = 0,
- LightColorUniform = 1,
- SizeUniform = 2,
- CenterFragcoordUniform = 3,
- CenterClipUniform = 4,
- RangeUniform = 5,
- ModeUniform = 6,
- FalloffUniform = 7,
+ SamplerUniform = 2,
+ LightColorUniform = 3,
+ SizeUniform = 4,
+ CenterFragcoordUniform = 5,
+ CenterClipUniform = 6,
+ RangeUniform = 7,
+ ModeUniform = 8,
+ FalloffUniform = 9,
};
enum : Int {
diff --git a/shaders/lightmap.vert b/shaders/lightmap.vert
index 90c5bc9c..aceaf4d5 100644
--- a/shaders/lightmap.vert
+++ b/shaders/lightmap.vert
@@ -1,13 +1,13 @@
precision mediump float;
-layout (location = 0) uniform sampler2D sampler;
-layout (location = 1) uniform vec3 light_color;
-layout (location = 2) uniform vec2 size;
-layout (location = 3) uniform vec2 center_fragcoord;
-layout (location = 4) uniform vec2 center_clip;
-layout (location = 5) uniform float range;
-layout (location = 6) uniform uint mode;
-layout (location = 7) uniform uint falloff;
+layout (location = 2) uniform sampler2D sampler0;
+layout (location = 3) uniform vec3 light_color;
+layout (location = 4) uniform vec2 size;
+layout (location = 5) uniform vec2 center_fragcoord;
+layout (location = 6) uniform vec2 center_clip;
+layout (location = 7) uniform float range;
+layout (location = 8) uniform uint mode;
+layout (location = 9) uniform uint falloff;
//layout (location = 0) out vec2 frag_texcoords;
//layout (location = 1) flat out vec2 frag_light_coord;