mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
lighting fix
This commit is contained in:
parent
31a90bd911
commit
0bbde3a778
4 changed files with 69 additions and 67 deletions
|
|
@ -55,7 +55,7 @@ void LightSolver::remove(int x, int y, int z) {
|
|||
}
|
||||
|
||||
void LightSolver::solve(Chunk* prevailingChunk) {
|
||||
const int coords[] = {
|
||||
static const int coords[] = {
|
||||
0, 0, 1,
|
||||
0, 0,-1,
|
||||
0, 1, 0,
|
||||
|
|
|
|||
|
|
@ -14,9 +14,8 @@
|
|||
|
||||
static debug::Logger logger("lighting");
|
||||
|
||||
Lighting::Lighting(const Content& content, Chunks& chunks)
|
||||
: content(content), chunks(chunks) {
|
||||
auto& indices = *content.getIndices();
|
||||
Lighting::Lighting(const ContentIndices& indices, Chunks& chunks)
|
||||
: indices(indices), chunks(chunks) {
|
||||
solverR = std::make_unique<LightSolver>(indices, chunks, 0);
|
||||
solverG = std::make_unique<LightSolver>(indices, chunks, 1);
|
||||
solverB = std::make_unique<LightSolver>(indices, chunks, 2);
|
||||
|
|
@ -70,7 +69,7 @@ void Lighting::prebuildSkyLight(Chunk& chunk, const ContentIndices& indices) {
|
|||
}
|
||||
|
||||
void Lighting::buildSkyLight(int cx, int cz){
|
||||
const auto blockDefs = content.getIndices()->blocks.getDefs();
|
||||
const auto blockDefs = indices.blocks.getDefs();
|
||||
|
||||
Chunk* chunk = chunks.getChunk(cx, cz);
|
||||
if (chunk == nullptr) {
|
||||
|
|
@ -110,7 +109,7 @@ void Lighting::onChunkLoaded(int cx, int cz, bool expand) {
|
|||
auto& solverB = *this->solverB;
|
||||
auto& solverS = *this->solverS;
|
||||
|
||||
auto blockDefs = content.getIndices()->blocks.getDefs();
|
||||
auto blockDefs = indices.blocks.getDefs();
|
||||
auto chunk = chunks.getChunk(cx, cz);
|
||||
if (chunk == nullptr) {
|
||||
logger.error() << "attempted to build lights to chunk missing in local matrix";
|
||||
|
|
@ -174,69 +173,72 @@ void Lighting::onChunkLoaded(int cx, int cz, bool expand) {
|
|||
}
|
||||
|
||||
void Lighting::onBlockSet(int x, int y, int z, blockid_t id){
|
||||
const auto& block = content.getIndices()->blocks.require(id);
|
||||
solverR->remove(x,y,z);
|
||||
solverG->remove(x,y,z);
|
||||
solverB->remove(x,y,z);
|
||||
const auto& block = indices.blocks.require(id);
|
||||
|
||||
if (id == 0){
|
||||
auto chunk = chunks.getChunkByVoxel(glm::ivec3{x, y, z});
|
||||
solverR->solve(chunk);
|
||||
solverG->solve(chunk);
|
||||
solverB->solve(chunk);
|
||||
if (chunks.getLight(x,y+1,z, 3) == 0xF){
|
||||
for (int i = y; i >= 0; i--){
|
||||
voxel* vox = chunks.get(x,i,z);
|
||||
if ((vox == nullptr || vox->id != 0) && block.skyLightPassing)
|
||||
auto chunk = chunks.getChunkByVoxel(glm::ivec3{x, y, z});
|
||||
|
||||
if (block.skyLightPassing) {
|
||||
if (chunks.getLight(x, y + 1, z, 3) == 0xF) {
|
||||
for (int i = y; i >= 0; i--) {
|
||||
voxel* vox = chunks.get(x, i, z);
|
||||
if (vox == nullptr ||
|
||||
indices.blocks.require(vox->id).skyLightPassing ==
|
||||
false)
|
||||
break;
|
||||
solverS->add(x,i,z, 0xF);
|
||||
solverS->add(x, i, z, 0xF);
|
||||
}
|
||||
}
|
||||
const int coords[] = {
|
||||
0, 0, 1,
|
||||
0, 0,-1,
|
||||
0, 1, 0,
|
||||
0,-1, 0,
|
||||
1, 0, 0,
|
||||
-1, 0, 0
|
||||
};
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int lx = x + coords[i * 3];
|
||||
int ly = y + coords[i * 3 + 1];
|
||||
int lz = z + coords[i * 3 + 2];
|
||||
|
||||
solverR->add(lx, ly, lz);
|
||||
solverG->add(lx, ly, lz);
|
||||
solverB->add(lx, ly, lz);
|
||||
solverS->add(lx, ly, lz);
|
||||
solverR->solve(chunk);
|
||||
solverG->solve(chunk);
|
||||
solverB->solve(chunk);
|
||||
solverS->solve(chunk);
|
||||
}
|
||||
} else {
|
||||
auto chunk = chunks.getChunkByVoxel(glm::ivec3{x, y, z});
|
||||
if (!block.skyLightPassing){
|
||||
solverS->remove(x,y,z);
|
||||
for (int i = y-1; i >= 0; i--){
|
||||
solverS->remove(x,i,z);
|
||||
if (i == 0 || chunks.get(x,i-1,z)->id != 0){
|
||||
break;
|
||||
}
|
||||
solverS->remove(x, y, z);
|
||||
for (int i = y - 1; i >= 0; i--) {
|
||||
voxel* vox = chunks.get(x, i, z);
|
||||
if (vox == nullptr ||
|
||||
indices.blocks.require(vox->id).skyLightPassing == false) {
|
||||
break;
|
||||
}
|
||||
solverS->solve(chunk);
|
||||
}
|
||||
solverR->solve(chunk);
|
||||
solverG->solve(chunk);
|
||||
solverB->solve(chunk);
|
||||
|
||||
if (block.emission[0] || block.emission[1] || block.emission[2]){
|
||||
solverR->add(x,y,z,block.emission[0]);
|
||||
solverG->add(x,y,z,block.emission[1]);
|
||||
solverB->add(x,y,z,block.emission[2]);
|
||||
solverR->solve(chunk);
|
||||
solverG->solve(chunk);
|
||||
solverB->solve(chunk);
|
||||
solverS->remove(x, i, z);
|
||||
}
|
||||
solverS->solve();
|
||||
}
|
||||
|
||||
solverR->remove(x, y, z);
|
||||
solverG->remove(x, y, z);
|
||||
solverB->remove(x, y, z);
|
||||
|
||||
solverR->solve(chunk);
|
||||
solverG->solve(chunk);
|
||||
solverB->solve(chunk);
|
||||
|
||||
static const int coords[] = {
|
||||
0, 0, 1,
|
||||
0, 0,-1,
|
||||
0, 1, 0,
|
||||
0,-1, 0,
|
||||
1, 0, 0,
|
||||
-1, 0, 0
|
||||
};
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int lx = x + coords[i * 3];
|
||||
int ly = y + coords[i * 3 + 1];
|
||||
int lz = z + coords[i * 3 + 2];
|
||||
|
||||
solverR->add(lx, ly, lz);
|
||||
solverG->add(lx, ly, lz);
|
||||
solverB->add(lx, ly, lz);
|
||||
solverS->add(lx, ly, lz);
|
||||
}
|
||||
|
||||
if (block.emission[0]) {
|
||||
solverR->add(x, y, z, block.emission[0]);
|
||||
}
|
||||
if (block.emission[1]) {
|
||||
solverG->add(x, y, z, block.emission[1]);
|
||||
}
|
||||
if (block.emission[2]) {
|
||||
solverB->add(x, y, z, block.emission[2]);
|
||||
}
|
||||
solverR->solve(chunk);
|
||||
solverG->solve(chunk);
|
||||
solverB->solve(chunk);
|
||||
solverS->solve(chunk);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,21 +2,20 @@
|
|||
|
||||
#include "typedefs.hpp"
|
||||
|
||||
class Content;
|
||||
class ContentIndices;
|
||||
class Chunk;
|
||||
class Chunks;
|
||||
class LightSolver;
|
||||
|
||||
class Lighting {
|
||||
const Content& content;
|
||||
const ContentIndices& indices;
|
||||
Chunks& chunks;
|
||||
std::unique_ptr<LightSolver> solverR;
|
||||
std::unique_ptr<LightSolver> solverG;
|
||||
std::unique_ptr<LightSolver> solverB;
|
||||
std::unique_ptr<LightSolver> solverS;
|
||||
public:
|
||||
Lighting(const Content& content, Chunks& chunks);
|
||||
Lighting(const ContentIndices& indices, Chunks& chunks);
|
||||
~Lighting();
|
||||
|
||||
void clear();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
|
||||
#include "content/Content.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "engine/EnginePaths.hpp"
|
||||
|
|
@ -41,7 +42,7 @@ LevelController::LevelController(
|
|||
|
||||
if (clientPlayer) {
|
||||
chunks->lighting = std::make_unique<Lighting>(
|
||||
level->content, *clientPlayer->chunks
|
||||
*level->content.getIndices(), *clientPlayer->chunks
|
||||
);
|
||||
}
|
||||
blocks = std::make_unique<BlocksController>(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue