Browse Source

more light propogation

testing
totallyfake 2 years ago
parent
commit
8ca7862cbd
3 changed files with 20 additions and 27 deletions
  1. 14
    10
      src/chunk.cpp
  2. 5
    15
      src/scenes/testscene.cpp
  3. 1
    2
      src/terraingen.cpp

+ 14
- 10
src/chunk.cpp View File

@@ -161,34 +161,34 @@ void Chunk::rebuildLighting() {
//FIRST PASS, block out all solid blocks
for (short i = 0; i < 4096; ++i) {
glm::ivec3 pos(i % 16, (i / 16) % 16,(i / 256)); // get current coord
mLighting[i].store(0);
auto lightVal = mLinkedWorld.voxelInfo.getEmission(getVoxelType(pos));

//set sunlighting if at the top of chunk and above the ground
if(pos.y == 15 &&
mLinkedWorld.getHeightMap(glm::ivec2(mPos.x, mPos.z))
->getHeight(glm::ivec2(pos.x, pos.z)) <=
->getHeight(glm::ivec2(pos.x, pos.z)) <
pos.y + mPos.y * 16)
{
lightVal = lightVal | 0xF; //max out the sun lighting
}
mLighting[i].store(lightVal);
if ((lightVal & 0xF) != 0) {
sunBFSQueue.push(std::make_tuple(i,this));
}

}

//iterate through sunlight
while (!sunBFSQueue.empty()) {
short index;
Chunk* chunk;
unsigned short light;
std::tie(index, chunk) = sunBFSQueue.front();
light = light & 0xF; // so I don't have to remask every time
glm::ivec3 pos( index % 16,
(index / 16) % 16,
index / 256);

unsigned short light;
light = chunk->getLightPacked(pos) & 0xF;

auto propogateSun =
@@ -198,15 +198,19 @@ void Chunk::rebuildLighting() {
auto checkPos = localPosToLocalPos(nChunk->getPos(), nPos);
nChunk = mLinkedWorld.getChunk(checkPos.first);
nPos = checkPos.second;
auto newLight = chunk->getLightPacked(nPos) & 0xF;
if (!chunk->isVoxelSolid(nPos)) {
if (nChunk == nullptr) {
return;
}
auto newLight = nChunk->getLightPacked(nPos) & 0xF;
if (!nChunk->isVoxelSolid(nPos)) {
if (light >= newLight + 2) {
if (straightDown) {
chunk->setLightPacked(nPos, (newLight & 0xFFF0) | 0xF);
nChunk->setLightPacked(nPos, (newLight & 0xFFF0) | 0xF);
} else {
nChunk->setLightPacked(nPos, (newLight & 0xFFF0) | light - 1);
}
chunk->setLightPacked(nPos, (newLight & 0xFFF0) | light - 1);
if (light - 1 > 1) {
sunBFSQueue.push(std::make_tuple((short)(nPos.x + 16 * (nPos.y + 16 * nPos.z)), chunk));
sunBFSQueue.push(std::make_tuple((short)(nPos.x + 16 * (nPos.y + 16 * nPos.z)), nChunk));
}
}
}

+ 5
- 15
src/scenes/testscene.cpp View File

@@ -92,20 +92,6 @@ void TestScene::init() {
handler.getEventSignal(SDL_QUIT ).connect<Game , &Game::stop >(linkedGame);
handler.getEventSignal(SDL_MOUSEMOTION).connect<TestScene, &TestScene::look>(this);

world.voxelInfo.setTextureData(1, Face3D::RIGHT, Orientation2D::UP, 0.0f);
world.voxelInfo.setTextureData(1, Face3D::LEFT, Orientation2D::UP, 0.0f);
world.voxelInfo.setTextureData(1, Face3D::TOP, Orientation2D::UP, 0.0f);
world.voxelInfo.setTextureData(1, Face3D::BOTTOM, Orientation2D::UP, 0.0f);
world.voxelInfo.setTextureData(1, Face3D::FRONT, Orientation2D::UP, 0.0f);
world.voxelInfo.setTextureData(1, Face3D::BACK, Orientation2D::UP, 0.0f);

world.voxelInfo.setTextureData(2, Face3D::RIGHT, Orientation2D::UP, 1.0f);
world.voxelInfo.setTextureData(2, Face3D::LEFT, Orientation2D::UP, 1.0f);
world.voxelInfo.setTextureData(2, Face3D::TOP, Orientation2D::UP, 2.0f);
world.voxelInfo.setTextureData(2, Face3D::BOTTOM, Orientation2D::UP, 1.0f);
world.voxelInfo.setTextureData(2, Face3D::FRONT, Orientation2D::UP, 1.0f);
world.voxelInfo.setTextureData(2, Face3D::BACK, Orientation2D::UP, 1.0f);


world.voxelInfo.setAllTextureIndexes(1, 0);
world.voxelInfo.setAllTextureIndexes(2, 1);
@@ -115,9 +101,13 @@ void TestScene::init() {
world.voxelInfo.setTransparent(1, false);
world.voxelInfo.setTransparent(2, false);

world.voxelInfo.setEmission(0, 0);
world.voxelInfo.setEmission(1, 0xF000);
world.voxelInfo.setEmission(2, 0);

std::cout << std::endl;

world.queueChunkLoadsAroundPoint(glm::vec3(0.0,0.0,0.0), 16);
world.queueChunkLoadsAroundPoint(glm::vec3(0.0,0.0,0.0), 8);

//world.forceGlobalGeometryUpdate();


+ 1
- 2
src/terraingen.cpp View File

@@ -58,8 +58,7 @@ void TerrainGen::generateChunk(Chunk* chunk) {
chunk->setVoxelType(i,j,k,1);
}
chunk->getHeightMap()->blockHeight(glm::ivec3(i,(chunkPos.y * 16) + j, k));
} else {
}
}
}
}
}

Loading…
Cancel
Save