mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 06:21:50 +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) {
|
void LightSolver::solve(Chunk* prevailingChunk) {
|
||||||
const int coords[] = {
|
static const int coords[] = {
|
||||||
0, 0, 1,
|
0, 0, 1,
|
||||||
0, 0,-1,
|
0, 0,-1,
|
||||||
0, 1, 0,
|
0, 1, 0,
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,8 @@
|
||||||
|
|
||||||
static debug::Logger logger("lighting");
|
static debug::Logger logger("lighting");
|
||||||
|
|
||||||
Lighting::Lighting(const Content& content, Chunks& chunks)
|
Lighting::Lighting(const ContentIndices& indices, Chunks& chunks)
|
||||||
: content(content), chunks(chunks) {
|
: indices(indices), chunks(chunks) {
|
||||||
auto& indices = *content.getIndices();
|
|
||||||
solverR = std::make_unique<LightSolver>(indices, chunks, 0);
|
solverR = std::make_unique<LightSolver>(indices, chunks, 0);
|
||||||
solverG = std::make_unique<LightSolver>(indices, chunks, 1);
|
solverG = std::make_unique<LightSolver>(indices, chunks, 1);
|
||||||
solverB = std::make_unique<LightSolver>(indices, chunks, 2);
|
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){
|
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);
|
Chunk* chunk = chunks.getChunk(cx, cz);
|
||||||
if (chunk == nullptr) {
|
if (chunk == nullptr) {
|
||||||
|
|
@ -110,7 +109,7 @@ void Lighting::onChunkLoaded(int cx, int cz, bool expand) {
|
||||||
auto& solverB = *this->solverB;
|
auto& solverB = *this->solverB;
|
||||||
auto& solverS = *this->solverS;
|
auto& solverS = *this->solverS;
|
||||||
|
|
||||||
auto blockDefs = content.getIndices()->blocks.getDefs();
|
auto blockDefs = indices.blocks.getDefs();
|
||||||
auto chunk = chunks.getChunk(cx, cz);
|
auto chunk = chunks.getChunk(cx, cz);
|
||||||
if (chunk == nullptr) {
|
if (chunk == nullptr) {
|
||||||
logger.error() << "attempted to build lights to chunk missing in local matrix";
|
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){
|
void Lighting::onBlockSet(int x, int y, int z, blockid_t id){
|
||||||
const auto& block = content.getIndices()->blocks.require(id);
|
const auto& block = indices.blocks.require(id);
|
||||||
solverR->remove(x,y,z);
|
|
||||||
solverG->remove(x,y,z);
|
|
||||||
solverB->remove(x,y,z);
|
|
||||||
|
|
||||||
if (id == 0){
|
auto chunk = chunks.getChunkByVoxel(glm::ivec3{x, y, z});
|
||||||
auto chunk = chunks.getChunkByVoxel(glm::ivec3{x, y, z});
|
|
||||||
solverR->solve(chunk);
|
if (block.skyLightPassing) {
|
||||||
solverG->solve(chunk);
|
if (chunks.getLight(x, y + 1, z, 3) == 0xF) {
|
||||||
solverB->solve(chunk);
|
for (int i = y; i >= 0; i--) {
|
||||||
if (chunks.getLight(x,y+1,z, 3) == 0xF){
|
voxel* vox = chunks.get(x, i, z);
|
||||||
for (int i = y; i >= 0; i--){
|
if (vox == nullptr ||
|
||||||
voxel* vox = chunks.get(x,i,z);
|
indices.blocks.require(vox->id).skyLightPassing ==
|
||||||
if ((vox == nullptr || vox->id != 0) && block.skyLightPassing)
|
false)
|
||||||
break;
|
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 {
|
} else {
|
||||||
auto chunk = chunks.getChunkByVoxel(glm::ivec3{x, y, z});
|
solverS->remove(x, y, z);
|
||||||
if (!block.skyLightPassing){
|
for (int i = y - 1; i >= 0; i--) {
|
||||||
solverS->remove(x,y,z);
|
voxel* vox = chunks.get(x, i, z);
|
||||||
for (int i = y-1; i >= 0; i--){
|
if (vox == nullptr ||
|
||||||
solverS->remove(x,i,z);
|
indices.blocks.require(vox->id).skyLightPassing == false) {
|
||||||
if (i == 0 || chunks.get(x,i-1,z)->id != 0){
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
solverS->solve(chunk);
|
solverS->remove(x, i, z);
|
||||||
}
|
|
||||||
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->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"
|
#include "typedefs.hpp"
|
||||||
|
|
||||||
class Content;
|
|
||||||
class ContentIndices;
|
class ContentIndices;
|
||||||
class Chunk;
|
class Chunk;
|
||||||
class Chunks;
|
class Chunks;
|
||||||
class LightSolver;
|
class LightSolver;
|
||||||
|
|
||||||
class Lighting {
|
class Lighting {
|
||||||
const Content& content;
|
const ContentIndices& indices;
|
||||||
Chunks& chunks;
|
Chunks& chunks;
|
||||||
std::unique_ptr<LightSolver> solverR;
|
std::unique_ptr<LightSolver> solverR;
|
||||||
std::unique_ptr<LightSolver> solverG;
|
std::unique_ptr<LightSolver> solverG;
|
||||||
std::unique_ptr<LightSolver> solverB;
|
std::unique_ptr<LightSolver> solverB;
|
||||||
std::unique_ptr<LightSolver> solverS;
|
std::unique_ptr<LightSolver> solverS;
|
||||||
public:
|
public:
|
||||||
Lighting(const Content& content, Chunks& chunks);
|
Lighting(const ContentIndices& indices, Chunks& chunks);
|
||||||
~Lighting();
|
~Lighting();
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "content/Content.hpp"
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "engine/EnginePaths.hpp"
|
#include "engine/EnginePaths.hpp"
|
||||||
|
|
@ -41,7 +42,7 @@ LevelController::LevelController(
|
||||||
|
|
||||||
if (clientPlayer) {
|
if (clientPlayer) {
|
||||||
chunks->lighting = std::make_unique<Lighting>(
|
chunks->lighting = std::make_unique<Lighting>(
|
||||||
level->content, *clientPlayer->chunks
|
*level->content.getIndices(), *clientPlayer->chunks
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
blocks = std::make_unique<BlocksController>(
|
blocks = std::make_unique<BlocksController>(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue