summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-06-10 19:17:21 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-06-10 19:17:21 +0200
commitaa5089b36453026ad33ce3cc3c11210774a45c84 (patch)
treefd54a9c53ea957d5dd34c746de1c7e09afae73a3
parenta0152f2c253dbf3c2c23d83a261d89e97310b430 (diff)
wip
-rw-r--r--serialize/world-impl.hpp3
-rw-r--r--serialize/world-reader.cpp13
-rw-r--r--serialize/world-writer.cpp2
-rw-r--r--shaders/lightmap.cpp7
-rw-r--r--shaders/lightmap.frag4
-rw-r--r--src/light-falloff.hpp4
6 files changed, 23 insertions, 10 deletions
diff --git a/serialize/world-impl.hpp b/serialize/world-impl.hpp
index f6e856f5..d56c432c 100644
--- a/serialize/world-impl.hpp
+++ b/serialize/world-impl.hpp
@@ -28,6 +28,7 @@
* 13) Entity counter initialized to 1024.
* 14) Always store entity offset, rework how sc_exact works.
* 15) Add light alpha.
+ * 16) One more bit for light falloff enum.
*/
namespace floormat {
@@ -48,7 +49,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 = 15;
+constexpr inline proto_t proto_version = 16;
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 c6b23999..f1492161 100644
--- a/serialize/world-reader.cpp
+++ b/serialize/world-reader.cpp
@@ -338,8 +338,17 @@ void reader_state::read_chunks(reader_t& s)
uint8_t flags; flags << s;
const bool exact = flags & 1;
proto.r = rotation((flags >> 1) & lowbits<rotation_BITS>);
- proto.falloff = light_falloff((flags >> 4) & lowbits<light_falloff_BITS>);
- const bool enabled = (flags >> 6) & 1;
+ bool enabled;
+ if (PROTO >= 16) [[likely]]
+ {
+ proto.falloff = light_falloff((flags >> 4) & lowbits<light_falloff_BITS>);
+ enabled = (flags >> 7) & 1;
+ }
+ else
+ {
+ proto.falloff = light_falloff((flags >> 4) & lowbits<2>);
+ enabled = (flags >> 6) & 1;
+ }
s >> proto.max_distance;
for (auto i = 0uz; i < 3; i++)
diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp
index 86f05b91..b07de09a 100644
--- a/serialize/world-writer.cpp
+++ b/serialize/world-writer.cpp
@@ -414,7 +414,7 @@ void writer_state::serialize_scenery(const chunk& c, writer_t& s)
flags |= (uint8_t)exact; // 1 bit
flags |= ((uint8_t)L.r & lowbits<rotation_BITS>) << 1; // 3 bits
flags |= ((uint8_t)L.falloff & lowbits<light_falloff_BITS>) << 4; // 2 bits
- flags |= (uint8_t)!!L.enabled << 6; // 1 bit
+ flags |= (uint8_t)!!L.enabled << 7; // 1 bit
s << flags;
}
{
diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp
index 7fa76d69..bc61a434 100644
--- a/shaders/lightmap.cpp
+++ b/shaders/lightmap.cpp
@@ -116,12 +116,15 @@ void lightmap_shader::add_light(Vector2i neighbor_offset, const light_s& light)
I = 1;
break;
case light_falloff::linear:
- I = std::fmax(1.f, light.dist * tile_size);
+ I = light.dist * tile_size / 5;
break;
case light_falloff::quadratic:
- I = std::fmax(1.f, light.dist * tile_size * 100);
+ I = light.dist * tile_size * 100;
break;
}
+
+ I = std::fmax(1.f, I);
+
auto I_clip = I * tile_size;
auto center = light.center + chunk_offset + Vector2(neighbor_offset)*chunk_size;
auto center_clip = Vector2{center} * scale; // clip coordinate
diff --git a/shaders/lightmap.frag b/shaders/lightmap.frag
index d560dcc6..db1cf895 100644
--- a/shaders/lightmap.frag
+++ b/shaders/lightmap.frag
@@ -14,9 +14,9 @@ void main() {
//float dist = sqrt(tmp.x*tmp.x + tmp.y*tmp.y);
float A = 1;
if (falloff == 0) // linear
- A = 1 - min(1, dist / I);
+ A = I/(I + dist);
else if (falloff == 2) // quadratic
- A = I/(1 + I + dist*dist);
+ A = I/(I + dist*dist);
//I = sqrt(color_intensity.w*1.5)*16;
//dist = sqrt(tmp.x*tmp.x + tmp.y*tmp.y);
//float alpha = 1 - min(1, dist / I);
diff --git a/src/light-falloff.hpp b/src/light-falloff.hpp
index 3d047731..f814cc5f 100644
--- a/src/light-falloff.hpp
+++ b/src/light-falloff.hpp
@@ -7,7 +7,7 @@ enum class light_falloff : uint8_t {
};
constexpr inline light_falloff light_falloff_COUNT{3};
-constexpr inline uint8_t light_falloff_BITS = 2;
-constexpr inline uint8_t light_falloff_MASK = (1 << 2)-1;
+constexpr inline uint8_t light_falloff_BITS = 3;
+constexpr inline uint8_t light_falloff_MASK = (1 << light_falloff_BITS)-1;
} // namespace floormat