summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/imgui.cpp43
-rw-r--r--editor/inspect-draw.cpp17
-rw-r--r--editor/inspect-types.cpp15
-rw-r--r--serialize/world-impl.hpp3
-rw-r--r--serialize/world-reader.cpp2
-rw-r--r--serialize/world-writer.cpp2
-rw-r--r--shaders/lightmap.cpp11
-rw-r--r--shaders/lightmap.frag3
-rw-r--r--shaders/lightmap.hpp2
-rw-r--r--shaders/lightmap.vert2
-rw-r--r--shaders/shader.hpp1
-rw-r--r--src/chunk-render.cpp2
-rw-r--r--src/entity.cpp6
-rw-r--r--src/entity.hpp1
-rw-r--r--src/light.hpp6
15 files changed, 68 insertions, 48 deletions
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index ddbbc918..b953a247 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -110,11 +110,13 @@ void app::draw_ui()
draw_clickables();
if (_render_vobjs)
draw_light_info();
+ const float main_menu_height = draw_main_menu();
+
+ [[maybe_unused]] auto font = font_saver{ctx.FontSize*dpi};
+
if (_tested_light)
draw_lightmap_test();
- const float main_menu_height = draw_main_menu();
- [[maybe_unused]] auto font = font_saver{ctx.FontSize*dpi};
if (_editor.current_tile_editor() || _editor.current_scenery_editor() || _editor.current_vobj_editor())
draw_editor_pane(main_menu_height);
draw_fps();
@@ -207,31 +209,32 @@ void app::draw_lightmap_test()
ImGui::SetNextWindowSize({1024, 1024});
auto& w = M->world();
- auto L = w.find_entity(_tested_light);
+ auto e_ = w.find_entity(_tested_light);
+
+ auto b1 = push_style_var(ImGuiStyleVar_WindowPadding, {0, 0});
- constexpr auto flags =
- ImGuiWindowFlags_NoTitleBar |
- ImGuiWindowFlags_NoResize |
- ImGuiWindowFlags_NoMove |
- ImGuiWindowFlags_NoScrollbar;
+ constexpr auto flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoScrollbar;
+ bool is_open = true;
- if (L && ImGui::Begin("Lightmap", nullptr, flags))
+ if (e_ && ImGui::Begin("Lightmap", &is_open, flags))
{
- fm_assert(L->type() == entity_type::light);
- auto& shader = M->lightmap_shader();
- light_s light {
- .center = {8 * 64, 8 * 64},
- .dist = 4,
- .color = {255, 255, 255},
- .falloff = light_falloff::linear,
+ constexpr auto chunk_size = TILE_SIZE2.sum()/2;
+ 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 * chunk_size,
+ .color = li.color,
+ .falloff = li.falloff,
};
- shader.begin({0, 0}, light);
+ auto& shader = M->lightmap_shader();
+ shader.begin({0, 0}, L);
shader.end();
- M->bind();
+ M->bind(); // todo
ImGui::Image(&shader.texture(), {1024, 1024});
- ImGui::End();
}
- else
+ ImGui::End();
+ if (!is_open)
_tested_light = 0;
}
diff --git a/editor/inspect-draw.cpp b/editor/inspect-draw.cpp
index d3c95e58..be32edf7 100644
--- a/editor/inspect-draw.cpp
+++ b/editor/inspect-draw.cpp
@@ -37,20 +37,21 @@ void app::draw_inspector()
continue;
}
auto& e = *e_;
- chunk_coords ch = e.coord.chunk();
- local_coords pos = e.coord.local();
- auto z = e.coord.z();
char buf[32];
- snformat(buf, "inspector-{:08x}"_cf, e.id);
-
- auto b1 = push_id(buf);
ImGui::SetNextWindowSize({375*dpi[0], 0});
+#if 0
auto name = loader.strip_prefix(e.atlas->name());
+ chunk_coords ch = e.coord.chunk();
+ local_coords pos = e.coord.local();
+auto z = e.coord.z();
if (z == 0)
- snformat(buf, "{} ({}x{} -> {}x{})"_cf, name, ch.x, ch.y, (int)pos.x, (int)pos.y);
+ snformat(buf, "{} ({}x{} -> {}x{})###inspector-{:08x}"_cf, name, ch.x, ch.y, (int)pos.x, (int)pos.y, e.id);
else
- snformat(buf, "{} ({}x{}:{} -> {}x{})"_cf, name, ch.x, ch.y, (int)z, (int)pos.x, (int)pos.y);
+ snformat(buf, "{} ({}x{}:{} -> {}x{})###inspector-{:08x}"_cf, name, ch.x, ch.y, (int)z, (int)pos.x, (int)pos.y, e.id);
+#else
+ snformat(buf, "inspector-{:08x}"_cf, e.id);
+#endif
bool is_open = true;
if (auto b2 = begin_window(buf, &is_open))
diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp
index c7d4b494..fc60992e 100644
--- a/editor/inspect-types.cpp
+++ b/editor/inspect-types.cpp
@@ -42,10 +42,11 @@ struct entity_accessors<entity> {
return constraints::range<uint16_t>{0, !x.atlas ? uint16_t(0) : uint16_t(x.atlas->info().nframes-1)};
},
},
- E::type<Vector2b>::field{"offset"_s,
- [](const entity& x) { return x.offset; },
- [](entity& x, Vector2b value) { x.set_bbox(value, x.bbox_offset, x.bbox_size, x.pass); },
- constantly(constraints::range{Vector2b(iTILE_SIZE2/-2), Vector2b(iTILE_SIZE2/2)}),
+ E::type<Vector2i>::field{"offset"_s,
+ [](const entity& x) { return Vector2i(x.offset); },
+ //[](entity& x, Vector2i value) { x.set_bbox(value, x.bbox_offset, x.bbox_size, x.pass); },
+ [](entity& x, Vector2i value) { x.move_to(value - Vector2i(x.offset)); },
+ //constantly(constraints::range{Vector2b(iTILE_SIZE2/-2), Vector2b(iTILE_SIZE2/2)}),
},
E::type<pass_mode>::field{"pass-mode"_s,
[](const entity& x) { return x.pass; },
@@ -210,10 +211,10 @@ struct entity_accessors<light>
using E = Entity<light>;
auto tuple0 = entity_accessors<entity>::accessors();
auto tuple = std::tuple{
- E::type<Color3ub>::field{"color"_s,
+ E::type<Color4ub>::field{"color"_s,
[](const light& x) { return x.color; },
- [](light& x, Color3ub value) { x.color = value; },
- constantly(constraints::range<Color3ub>{{0, 0, 0}, {255, 255, 255}}),
+ [](light& x, Color4ub value) { x.color = value; },
+ constantly(constraints::range<Color4ub>{{0, 0, 0, 0}, {255, 255, 255, 255}}),
},
E::type<light_falloff>::field{"falloff"_s,
[](const light& x) { return x.falloff; },
diff --git a/serialize/world-impl.hpp b/serialize/world-impl.hpp
index fc7fe79c..f6e856f5 100644
--- a/serialize/world-impl.hpp
+++ b/serialize/world-impl.hpp
@@ -27,6 +27,7 @@
* 12) Don't write entity name twice.
* 13) Entity counter initialized to 1024.
* 14) Always store entity offset, rework how sc_exact works.
+ * 15) Add light alpha.
*/
namespace floormat {
@@ -47,7 +48,7 @@ template<typename T> constexpr inline T int_max = std::numeric_limits<T>::max();
#define file_magic ".floormat.save"
-constexpr inline proto_t proto_version = 14;
+constexpr inline proto_t proto_version = 15;
constexpr inline size_t atlas_name_max = 128;
constexpr inline auto null_atlas = (atlasid)-1LL;
diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp
index 170f9c97..c6b23999 100644
--- a/serialize/world-reader.cpp
+++ b/serialize/world-reader.cpp
@@ -344,6 +344,8 @@ void reader_state::read_chunks(reader_t& s)
s >> proto.max_distance;
for (auto i = 0uz; i < 3; i++)
s >> proto.color[i];
+ if (PROTO >= 15) [[likely]]
+ s >> proto.color[3];
if (!exact)
{
uint16_t frame; frame << s;
diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp
index 5620c782..86f05b91 100644
--- a/serialize/world-writer.cpp
+++ b/serialize/world-writer.cpp
@@ -419,7 +419,7 @@ void writer_state::serialize_scenery(const chunk& c, writer_t& s)
}
{
s << L.max_distance;
- for (auto i = 0uz; i < 3; i++)
+ for (auto i = 0uz; i < 4; i++)
s << L.color[i];
}
if (!exact)
diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp
index a599cfc9..3a2d339a 100644
--- a/shaders/lightmap.cpp
+++ b/shaders/lightmap.cpp
@@ -109,8 +109,8 @@ void lightmap_shader::add_light(Vector2i neighbor_offset, const light_s& light)
constexpr auto tile_size = TILE_SIZE2.sum()/2;
constexpr auto scale = 2/chunk_size;
- auto dist = std::fmax(0.f, light.dist * tile_size);
- auto dist_clip = dist * tile_size;
+ auto dist = std::fmax(0.f, light.dist/* * tile_size*/);
+ auto dist_clip = dist/* * tile_size*/;
auto center = light.center + chunk_offset + Vector2(neighbor_offset)*chunk_size;
auto center_clip = Vector2{center} * scale; // clip coordinate
constexpr auto image_size_factor = Vector2(image_size) / Vector2(chunk_size);
@@ -126,7 +126,10 @@ void lightmap_shader::add_light(Vector2i neighbor_offset, const light_s& light)
_count++;
- setUniform(ColorIntensityUniform, Vector4{Vector3{light.color}, dist});
+ float alpha = light.color.a() / 255.f;
+ auto color = Vector3{light.color.rgb()} / 255.f;
+
+ setUniform(ColorIntensityUniform, Vector4{Vector3{color} * alpha, dist});
setUniform(CenterUniform, center_fragcoord);
setUniform(FalloffUniform, (uint32_t)light.falloff);
setUniform(SizeUniform, chunk_size);
@@ -136,7 +139,7 @@ lightmap_shader::~lightmap_shader() = default;
void lightmap_shader::clear()
{
- framebuffer.fb.clearColor(0, Color4{1.f, 0.f, 1.f, 1.f});
+ framebuffer.fb.clearColor(0, Vector4ui{0});
//framebuffer.fb.clearDepth(0);
}
diff --git a/shaders/lightmap.frag b/shaders/lightmap.frag
index 748be244..eb7ed789 100644
--- a/shaders/lightmap.frag
+++ b/shaders/lightmap.frag
@@ -11,7 +11,8 @@ void main() {
vec2 pos = gl_FragCoord.xy;
float I = color_intensity.w;
vec2 tmp = pos - center;
+ //float dist = sqrt(tmp.x*tmp.x + tmp.y*tmp.y);
float dist = sqrt(tmp.x*tmp.x + tmp.y*tmp.y);
float alpha = 1 - min(1, dist / I);
- color = vec4(alpha * color_intensity.xyz, 1);
+ color = vec4(color_intensity.xyz, alpha);
}
diff --git a/shaders/lightmap.hpp b/shaders/lightmap.hpp
index a7204723..e458cadc 100644
--- a/shaders/lightmap.hpp
+++ b/shaders/lightmap.hpp
@@ -20,7 +20,7 @@ struct light_s final
Vector2 center;
float dist = 1;
//float depth = -1 + 1e-4f;
- Math::Color3<uint8_t> color {255, 255, 255};
+ Math::Color4<uint8_t> color;
light_falloff falloff = light_falloff::linear;
bool operator==(const light_s&) const noexcept;
diff --git a/shaders/lightmap.vert b/shaders/lightmap.vert
index a044a141..7b1ca696 100644
--- a/shaders/lightmap.vert
+++ b/shaders/lightmap.vert
@@ -8,5 +8,5 @@ layout (location = 3) uniform vec2 size;
layout (location = 0) in vec4 position;
void main() {
- gl_Position = vec4(position.x, -position.y, 0, 1);
+ gl_Position = vec4(position.x, position.y, 0, 1);
}
diff --git a/shaders/shader.hpp b/shaders/shader.hpp
index 7e73974b..0f7100e0 100644
--- a/shaders/shader.hpp
+++ b/shaders/shader.hpp
@@ -37,6 +37,7 @@ struct tile_shader final : GL::AbstractShaderProgram
static constexpr Vector2s max_screen_tiles = {8, 8};
static constexpr float character_depth_offset = 1 + 1./64;
static constexpr float scenery_depth_offset = 1 + 1./64;
+ static constexpr float ground_depth_offset = 0; // todo scenery cut off at chunk boundary
static constexpr float wall_depth_offset = 1;
static constexpr float z_depth_offset = 1 + 2./64;
static constexpr float depth_tile_size = 1/(double)(TILE_MAX_DIM * 2 * max_screen_tiles.product());
diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp
index 87f44e79..38d35030 100644
--- a/src/chunk-render.cpp
+++ b/src/chunk-render.cpp
@@ -40,7 +40,7 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple
const local_coords pos{i};
const auto quad = atlas->floor_quad(Vector3(pos) * TILE_SIZE, TILE_SIZE2);
const auto texcoords = atlas->texcoords_for_id(_ground_variants[i]);
- const float depth = tile_shader::depth_value(pos);
+ const float depth = tile_shader::depth_value(pos, tile_shader::ground_depth_offset);
auto& v = vertexes[k];
for (auto j = 0uz; j < 4; j++)
v[j] = { quad[j], texcoords[j], depth };
diff --git a/src/entity.cpp b/src/entity.cpp
index 6361c118..905fc8d0 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -239,6 +239,12 @@ size_t entity::move_to(size_t& i, Vector2i delta, rotation new_r)
return i;
}
+void entity::move_to(Magnum::Vector2i delta)
+{
+ auto i = index();
+ (void)move_to(i, delta, r);
+}
+
void entity::set_bbox_(Vector2b offset_, Vector2b bbox_offset_, Vector2ub bbox_size_, pass_mode pass_)
{
const_cast<Vector2b&>(offset) = offset_;
diff --git a/src/entity.hpp b/src/entity.hpp
index 21628a19..29777c13 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -77,6 +77,7 @@ struct entity
bool can_rotate(rotation new_r);
bool can_move_to(Vector2i delta);
size_t move_to(size_t& i, Vector2i delta, rotation new_r);
+ void move_to(Vector2i delta);
protected:
entity(object_id id, struct chunk& c, const entity_proto& proto);
diff --git a/src/light.hpp b/src/light.hpp
index 1332efc3..45c8390e 100644
--- a/src/light.hpp
+++ b/src/light.hpp
@@ -16,7 +16,7 @@ struct light_proto : entity_proto
bool operator==(const light_proto&) const;
float max_distance = 0;
- Color3ub color{255, 255, 255};
+ Color4ub color{255, 255, 255, 255};
light_falloff falloff : 3 = light_falloff::linear;
uint8_t enabled : 1 = true;
};
@@ -24,9 +24,9 @@ struct light_proto : entity_proto
struct light final : entity
{
float max_distance;
- Color3ub color;
+ Color4ub color;
light_falloff falloff : 2;
- uint8_t enabled : 1 = true;
+ uint8_t enabled : 1;
light(object_id id, struct chunk& c, const light_proto& proto);