diff --git a/src/engine.cpp b/src/engine.cpp index 3f0e014e..ed59fdc6 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -16,15 +16,6 @@ #include "window/input.h" #include "graphics/Batch2D.h" #include "graphics/ImageData.h" -#include "world/World.h" -#include "world/Level.h" -#include "voxels/Chunk.h" -#include "voxels/Chunks.h" -#include "voxels/ChunksController.h" -#include "voxels/ChunksStorage.h" -#include "objects/Player.h" -#include "frontend/world_render.h" -#include "frontend/hud.h" #include "frontend/gui/GUI.h" #include "frontend/screens.h" #include "util/platform.h" @@ -133,4 +124,4 @@ void Engine::setScreen(shared_ptr screen) { const Content* Engine::getContent() const { return content; -} \ No newline at end of file +} diff --git a/src/graphics/BlocksRenderer.cpp b/src/graphics/BlocksRenderer.cpp index e7126a3d..4caabf92 100644 --- a/src/graphics/BlocksRenderer.cpp +++ b/src/graphics/BlocksRenderer.cpp @@ -346,7 +346,7 @@ void BlocksRenderer::render(const voxel* voxels, int atlas_size) { Mesh* BlocksRenderer::render(const Chunk* chunk, int atlas_size, const ChunksStorage* chunks) { this->chunk = chunk; voxelsBuffer->setPosition(chunk->x * CHUNK_W - 1, 0, chunk->z * CHUNK_D - 1); - chunks->getVoxels(voxelsBuffer); + chunks->getVoxels(voxelsBuffer, true); overflow = false; vertexOffset = 0; indexOffset = indexSize = 0; diff --git a/src/lighting/Lightmap.h b/src/lighting/Lightmap.h index f8a329dc..2e774dc1 100644 --- a/src/lighting/Lightmap.h +++ b/src/lighting/Lightmap.h @@ -71,6 +71,10 @@ public: return map; } + static inline light_t combine(int r, int g, int b, int s) { + return r | (g << 4) | (b << 8) | (s << 12); + } + static inline light_t extract(light_t light, ubyte channel) { return (light >> (channel << 2)) & 0xF; } diff --git a/src/voxels/ChunksStorage.cpp b/src/voxels/ChunksStorage.cpp index 50624f1a..6b98905e 100644 --- a/src/voxels/ChunksStorage.cpp +++ b/src/voxels/ChunksStorage.cpp @@ -4,6 +4,8 @@ #include "VoxelsVolume.h" #include "Chunk.h" +#include "Block.h" +#include "../content/Content.h" #include "../files/WorldFiles.h" #include "../world/Level.h" #include "../world/World.h" @@ -52,7 +54,9 @@ std::shared_ptr ChunksStorage::create(int x, int z) { } // some magic code -void ChunksStorage::getVoxels(VoxelsVolume* volume) const { +void ChunksStorage::getVoxels(VoxelsVolume* volume, bool backlight) const { + const Content* content = level->content; + const ContentIndices* indices = content->indices; voxel* voxels = volume->getVoxels(); light_t* lights = volume->getLights(); int x = volume->getX(); @@ -106,7 +110,19 @@ void ChunksStorage::getVoxels(VoxelsVolume* volume) const { uint cidx = vox_index(lx - cx * CHUNK_W, ly, lz - cz * CHUNK_D, CHUNK_W, CHUNK_D); voxels[vidx] = cvoxels[cidx]; - lights[vidx] = clights[cidx]; + light_t light = clights[cidx]; + if (backlight) { + const Block* block = indices->getBlockDef(voxels[vidx].id); + if (block->lightPassing) { + light = Lightmap::combine( + min(15, Lightmap::extract(light, 0)+1), + min(15, Lightmap::extract(light, 1)+1), + min(15, Lightmap::extract(light, 2)+1), + min(15, Lightmap::extract(light, 3)+1) + ); + } + } + lights[vidx] = light; } } } diff --git a/src/voxels/ChunksStorage.h b/src/voxels/ChunksStorage.h index fbd96a70..e6549c5a 100644 --- a/src/voxels/ChunksStorage.h +++ b/src/voxels/ChunksStorage.h @@ -23,7 +23,7 @@ public: std::shared_ptr get(int x, int z) const; void store(std::shared_ptr chunk); void remove(int x, int y); - void getVoxels(VoxelsVolume* volume) const; + void getVoxels(VoxelsVolume* volume, bool backlight=false) const; std::shared_ptr create(int x, int z); light_t getLight(int x, int y, int z, ubyte channel) const;