add Lightmap::extractNormalized

This commit is contained in:
MihailRis 2025-12-20 23:26:50 +03:00
parent 4417eb7685
commit 54d1398d1b
4 changed files with 16 additions and 4 deletions

View file

@ -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);
}

View file

@ -5,6 +5,7 @@
#include <memory>
#include <cstring>
#include <glm/vec4.hpp>
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<ubyte[]> encode() const;
void decode(const ubyte* src);

View file

@ -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;

View file

@ -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);