|
@@ -301,34 +301,40 @@ void DX12ChunkData::updateLightning(Chunk* zChunk)
|
|
|
dxLightBuffer->setLength(neededSize);
|
|
dxLightBuffer->setLength(neededSize);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- Directions vertexDirections[] = {TOP | NORTH | EAST,
|
|
|
|
|
- TOP | SOUTH | EAST,
|
|
|
|
|
- TOP | SOUTH | WEST,
|
|
|
|
|
- TOP | NORTH | WEST,
|
|
|
|
|
- BOTTOM | NORTH | EAST,
|
|
|
|
|
- BOTTOM | SOUTH | EAST,
|
|
|
|
|
- BOTTOM | SOUTH | WEST,
|
|
|
|
|
- BOTTOM | NORTH | WEST};
|
|
|
|
|
|
|
+ Directions vertexDirections[8][3] = {
|
|
|
|
|
+ {TOP, NORTH, EAST},
|
|
|
|
|
+ {TOP, SOUTH, EAST},
|
|
|
|
|
+ {TOP, SOUTH, WEST},
|
|
|
|
|
+ {TOP, NORTH, WEST},
|
|
|
|
|
+ {BOTTOM, NORTH, EAST},
|
|
|
|
|
+ {BOTTOM, SOUTH, EAST},
|
|
|
|
|
+ {BOTTOM, SOUTH, WEST},
|
|
|
|
|
+ {BOTTOM, NORTH, WEST}
|
|
|
|
|
+ };
|
|
|
|
|
+ const unsigned char noLightData[6] = {0, 0, 0, 0, 0, 0};
|
|
|
for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; ++i)
|
|
for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; ++i)
|
|
|
{
|
|
{
|
|
|
if (blockIndices[i] >= 0)
|
|
if (blockIndices[i] >= 0)
|
|
|
{
|
|
{
|
|
|
Vec3<int> blockLocation = Chunk::chunkCoordinates(i);
|
|
Vec3<int> blockLocation = Chunk::chunkCoordinates(i);
|
|
|
Block* zBlock = zChunk->zBlockAt(blockLocation);
|
|
Block* zBlock = zChunk->zBlockAt(blockLocation);
|
|
|
- int offset = blockIndices[i] * 8;
|
|
|
|
|
- for (int j = 0; j < 8; ++j)
|
|
|
|
|
|
|
+ union
|
|
|
{
|
|
{
|
|
|
- Directions dir = vertexDirections[j];
|
|
|
|
|
- int lightData[6];
|
|
|
|
|
- memset(lightData, 0, sizeof(int) * 6);
|
|
|
|
|
- int count = 0;
|
|
|
|
|
- for (int d = 0; d < 6; d++)
|
|
|
|
|
|
|
+ const unsigned char* neighborLightMap[3][3][3];
|
|
|
|
|
+ const unsigned char* neighborLightMapEntries[3 * 3 * 3];
|
|
|
|
|
+ };
|
|
|
|
|
+ for (int j = 0; j < 3 * 3 * 3; j++)
|
|
|
|
|
+ {
|
|
|
|
|
+ neighborLightMapEntries[j] = noLightData;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (int x = -1; x <= 1; ++x)
|
|
|
|
|
+ {
|
|
|
|
|
+ for (int y = -1; y <= 1; ++y)
|
|
|
{
|
|
{
|
|
|
- Direction direction = getDirectionFromIndex(d);
|
|
|
|
|
- if ((dir | direction) == dir)
|
|
|
|
|
|
|
+ for (int z = -1; z <= 1; ++z)
|
|
|
{
|
|
{
|
|
|
Vec3<int> neighborLocation
|
|
Vec3<int> neighborLocation
|
|
|
- = blockLocation + getDirection(direction);
|
|
|
|
|
|
|
+ = blockLocation + Vec3<int>(x, y, z);
|
|
|
if (neighborLocation.z >= 0
|
|
if (neighborLocation.z >= 0
|
|
|
&& neighborLocation.z < WORLD_HEIGHT)
|
|
&& neighborLocation.z < WORLD_HEIGHT)
|
|
|
{
|
|
{
|
|
@@ -337,40 +343,59 @@ void DX12ChunkData::updateLightning(Chunk* zChunk)
|
|
|
&& neighborLocation.y >= 0
|
|
&& neighborLocation.y >= 0
|
|
|
&& neighborLocation.y < CHUNK_SIZE)
|
|
&& neighborLocation.y < CHUNK_SIZE)
|
|
|
{
|
|
{
|
|
|
- int index = Chunk::index(neighborLocation);
|
|
|
|
|
- if (blockIndices[index] < 0)
|
|
|
|
|
- {
|
|
|
|
|
- for (int k = 0; k < 6; ++k)
|
|
|
|
|
- {
|
|
|
|
|
- lightData[k]
|
|
|
|
|
- += (int)zBlock->getLightData(
|
|
|
|
|
- direction)[k];
|
|
|
|
|
- }
|
|
|
|
|
- ++count;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- if (!World::INSTANCE->zBlockAt(
|
|
|
|
|
- neighborLocation
|
|
|
|
|
- + Vec3<int>(zChunk->getCenter().x
|
|
|
|
|
- - CHUNK_SIZE / 2,
|
|
|
|
|
- zChunk->getCenter().y
|
|
|
|
|
- - CHUNK_SIZE / 2,
|
|
|
|
|
- 0)))
|
|
|
|
|
|
|
+ Block* zNeighborBlock
|
|
|
|
|
+ = zChunk->zBlockAt(neighborLocation);
|
|
|
|
|
+ if (zNeighborBlock)
|
|
|
{
|
|
{
|
|
|
- for (int k = 0; k < 6; ++k)
|
|
|
|
|
|
|
+ for (int d = 0; d < 6; d++)
|
|
|
{
|
|
{
|
|
|
- lightData[k]
|
|
|
|
|
- += (int)zBlock->getLightData(
|
|
|
|
|
- direction)[k];
|
|
|
|
|
|
|
+ Vec3<int> lmi
|
|
|
|
|
+ = getDirection(
|
|
|
|
|
+ getDirectionFromIndex(d))
|
|
|
|
|
+ + Vec3<int>(x, y, z);
|
|
|
|
|
+ if (lmi.x >= -1 && lmi.x <= 1
|
|
|
|
|
+ && lmi.y >= -1 && lmi.y <= 1
|
|
|
|
|
+ && lmi.z >= -1 && lmi.z <= 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ neighborLightMap[lmi.x + 1]
|
|
|
|
|
+ [lmi.y + 1]
|
|
|
|
|
+ [lmi.z + 1]
|
|
|
|
|
+ = zNeighborBlock->getLightData(
|
|
|
|
|
+ getDirectionFromIndex(d));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- ++count;
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
+ int offset = blockIndices[i] * 8;
|
|
|
|
|
+ for (int j = 0; j < 8; ++j)
|
|
|
|
|
+ {
|
|
|
|
|
+ int lightData[6];
|
|
|
|
|
+ memset(lightData, 0, sizeof(int) * 6);
|
|
|
|
|
+ int count = 0;
|
|
|
|
|
+ for (int d = 1; d < 8; d++)
|
|
|
|
|
+ {
|
|
|
|
|
+ Directions direction = vertexDirections[j][0] * ((d & 0x1) != 0)
|
|
|
|
|
+ + vertexDirections[j][1] * ((d & 0x2) != 0)
|
|
|
|
|
+ + vertexDirections[j][2] * ((d & 0x4) != 0);
|
|
|
|
|
+ Vec3<int> index = getDirection(direction);
|
|
|
|
|
+ bool notZero = 0;
|
|
|
|
|
+ const unsigned char* currentLight
|
|
|
|
|
+ = neighborLightMap[index.x + 1][index.y + 1]
|
|
|
|
|
+ [index.z + 1];
|
|
|
|
|
+ for (int k = 0; k < 6; ++k)
|
|
|
|
|
+ {
|
|
|
|
|
+ lightData[k] += (int)currentLight[k];
|
|
|
|
|
+ notZero |= currentLight[k] > 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (notZero)
|
|
|
|
|
+ {
|
|
|
|
|
+ ++count;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
for (int k = 0; k < 6; ++k)
|
|
for (int k = 0; k < 6; ++k)
|
|
|
{
|
|
{
|
|
|
lightBuffer[offset + j * 6 + k]
|
|
lightBuffer[offset + j * 6 + k]
|