From 54d1398d1be8b52cc59196d91c13817b523e2582 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 20 Dec 2025 23:26:50 +0300 Subject: [PATCH] add Lightmap::extractNormalized --- src/graphics/render/BlocksRenderer.cpp | 5 +---- src/lighting/Lightmap.hpp | 10 ++++++++++ src/voxels/Chunks.cpp | 4 ++++ src/voxels/Chunks.hpp | 1 + 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/graphics/render/BlocksRenderer.cpp b/src/graphics/render/BlocksRenderer.cpp index 8466008da..5320edd73 100644 --- a/src/graphics/render/BlocksRenderer.cpp +++ b/src/graphics/render/BlocksRenderer.cpp @@ -452,10 +452,7 @@ glm::vec4 BlocksRenderer::pickLight(int x, int y, int z) const { if (isOpenForLight(x, y, z)) { light_t light = voxelsBuffer->pickLight(chunk->x * CHUNK_W + x, y, chunk->z * CHUNK_D + z); - return glm::vec4(Lightmap::extract(light, 0), - Lightmap::extract(light, 1), - Lightmap::extract(light, 2), - Lightmap::extract(light, 3)) / 15.0f; + return Lightmap::extractNormalized(light); } else { return glm::vec4(0.0f); } diff --git a/src/lighting/Lightmap.hpp b/src/lighting/Lightmap.hpp index 858e37388..c13058904 100644 --- a/src/lighting/Lightmap.hpp +++ b/src/lighting/Lightmap.hpp @@ -5,6 +5,7 @@ #include #include +#include inline constexpr int LIGHTMAP_DATA_LEN = CHUNK_VOL/2; @@ -87,6 +88,15 @@ public: return (light >> (channel << 2)) & 0xF; } + static glm::vec4 extractNormalized(light_t light) { + return glm::vec4( + extract(light, 0) / 15.0f, + extract(light, 1) / 15.0f, + extract(light, 2) / 15.0f, + extract(light, 3) / 15.0f + ); + } + std::unique_ptr encode() const; void decode(const ubyte* src); diff --git a/src/voxels/Chunks.cpp b/src/voxels/Chunks.cpp index 96c709639..1233f089c 100644 --- a/src/voxels/Chunks.cpp +++ b/src/voxels/Chunks.cpp @@ -100,6 +100,10 @@ bool Chunks::isObstacleBlock(int32_t x, int32_t y, int32_t z) { return indices.blocks.require(v->id).obstacle; } +ubyte Chunks::getLight(const glm::ivec3& pos) const { + return getLight(pos.x, pos.y, pos.z); +} + ubyte Chunks::getLight(int32_t x, int32_t y, int32_t z, int channel) const { if (y < 0 || y >= CHUNK_H) { return 0; diff --git a/src/voxels/Chunks.hpp b/src/voxels/Chunks.hpp index 2448d8333..94fac08ce 100644 --- a/src/voxels/Chunks.hpp +++ b/src/voxels/Chunks.hpp @@ -76,6 +76,7 @@ public: return get(pos.x, pos.y, pos.z); } + ubyte getLight(const glm::ivec3& pos) const; light_t getLight(int32_t x, int32_t y, int32_t z) const; ubyte getLight(int32_t x, int32_t y, int32_t z, int channel) const; void set(int32_t x, int32_t y, int32_t z, uint32_t id, blockstate state);