Backlight for tranparent blocks
This commit is contained in:
parent
d2c87f4ba5
commit
b472626d8d
@ -16,15 +16,6 @@
|
|||||||
#include "window/input.h"
|
#include "window/input.h"
|
||||||
#include "graphics/Batch2D.h"
|
#include "graphics/Batch2D.h"
|
||||||
#include "graphics/ImageData.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/gui/GUI.h"
|
||||||
#include "frontend/screens.h"
|
#include "frontend/screens.h"
|
||||||
#include "util/platform.h"
|
#include "util/platform.h"
|
||||||
@ -133,4 +124,4 @@ void Engine::setScreen(shared_ptr<Screen> screen) {
|
|||||||
|
|
||||||
const Content* Engine::getContent() const {
|
const Content* Engine::getContent() const {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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) {
|
Mesh* BlocksRenderer::render(const Chunk* chunk, int atlas_size, const ChunksStorage* chunks) {
|
||||||
this->chunk = chunk;
|
this->chunk = chunk;
|
||||||
voxelsBuffer->setPosition(chunk->x * CHUNK_W - 1, 0, chunk->z * CHUNK_D - 1);
|
voxelsBuffer->setPosition(chunk->x * CHUNK_W - 1, 0, chunk->z * CHUNK_D - 1);
|
||||||
chunks->getVoxels(voxelsBuffer);
|
chunks->getVoxels(voxelsBuffer, true);
|
||||||
overflow = false;
|
overflow = false;
|
||||||
vertexOffset = 0;
|
vertexOffset = 0;
|
||||||
indexOffset = indexSize = 0;
|
indexOffset = indexSize = 0;
|
||||||
|
|||||||
@ -71,6 +71,10 @@ public:
|
|||||||
return map;
|
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) {
|
static inline light_t extract(light_t light, ubyte channel) {
|
||||||
return (light >> (channel << 2)) & 0xF;
|
return (light >> (channel << 2)) & 0xF;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include "VoxelsVolume.h"
|
#include "VoxelsVolume.h"
|
||||||
#include "Chunk.h"
|
#include "Chunk.h"
|
||||||
|
#include "Block.h"
|
||||||
|
#include "../content/Content.h"
|
||||||
#include "../files/WorldFiles.h"
|
#include "../files/WorldFiles.h"
|
||||||
#include "../world/Level.h"
|
#include "../world/Level.h"
|
||||||
#include "../world/World.h"
|
#include "../world/World.h"
|
||||||
@ -52,7 +54,9 @@ std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// some magic code
|
// 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();
|
voxel* voxels = volume->getVoxels();
|
||||||
light_t* lights = volume->getLights();
|
light_t* lights = volume->getLights();
|
||||||
int x = volume->getX();
|
int x = volume->getX();
|
||||||
@ -106,7 +110,19 @@ void ChunksStorage::getVoxels(VoxelsVolume* volume) const {
|
|||||||
uint cidx = vox_index(lx - cx * CHUNK_W, ly,
|
uint cidx = vox_index(lx - cx * CHUNK_W, ly,
|
||||||
lz - cz * CHUNK_D, CHUNK_W, CHUNK_D);
|
lz - cz * CHUNK_D, CHUNK_W, CHUNK_D);
|
||||||
voxels[vidx] = cvoxels[cidx];
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ public:
|
|||||||
std::shared_ptr<Chunk> get(int x, int z) const;
|
std::shared_ptr<Chunk> get(int x, int z) const;
|
||||||
void store(std::shared_ptr<Chunk> chunk);
|
void store(std::shared_ptr<Chunk> chunk);
|
||||||
void remove(int x, int y);
|
void remove(int x, int y);
|
||||||
void getVoxels(VoxelsVolume* volume) const;
|
void getVoxels(VoxelsVolume* volume, bool backlight=false) const;
|
||||||
std::shared_ptr<Chunk> create(int x, int z);
|
std::shared_ptr<Chunk> create(int x, int z);
|
||||||
|
|
||||||
light_t getLight(int x, int y, int z, ubyte channel) const;
|
light_t getLight(int x, int y, int z, ubyte channel) const;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user