Skip to content

Commit

Permalink
[BlockMesher|LightUtils] Disabled AO for multibox draw type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Jul 11, 2021
1 parent 965ced0 commit 19355e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
9 changes: 6 additions & 3 deletions source/client/world/mesh/BlockMesher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,18 @@ void BlockMesher::addBlockFace(s8f x, s8f y, s8f z, s8f f, ChunkMeshBuildingJob
vertices[v].texCoord[0] = gk::qlerpf(blockTexCoords.x, blockTexCoords.x + blockTexCoords.sizeX, U);
vertices[v].texCoord[1] = gk::qlerpf(blockTexCoords.y, blockTexCoords.y + blockTexCoords.sizeY, V);

// Lighting-based implementation
bool useAO = Config::ambientOcclusion == 2 && blockState.drawType() != BlockDrawType::Multibox;

if (Config::isSmoothLightingEnabled)
vertices[v].lightValue[0] = getLightForVertex(LightType::Sun, x, y, z, *neighbourOfs[v], normal, job.chunkData);
vertices[v].lightValue[0] = getLightForVertex(LightType::Sun, x, y, z, *neighbourOfs[v], normal, job.chunkData, useAO);
else if (blockState.isOpaque())
vertices[v].lightValue[0] = job.chunkData.getSunlight(sx, sy, sz);
else
vertices[v].lightValue[0] = job.chunkData.getSunlight(x, y, z);

if (Config::isSmoothLightingEnabled && !blockState.isLightSource())
vertices[v].lightValue[1] = getLightForVertex(LightType::Torch, x, y, z, *neighbourOfs[v], normal, job.chunkData);
vertices[v].lightValue[1] = getLightForVertex(LightType::Torch, x, y, z, *neighbourOfs[v], normal, job.chunkData, useAO);
else if (blockState.isOpaque())
vertices[v].lightValue[1] = job.chunkData.getTorchlight(sx, sy, sz);
else
Expand All @@ -218,7 +221,7 @@ void BlockMesher::addBlockFace(s8f x, s8f y, s8f z, s8f f, ChunkMeshBuildingJob
}

auto addVertex = [&](u8 v) {
if (Config::ambientOcclusion != 1 || blockState.isLightSource())
if (Config::ambientOcclusion != 1 || blockState.isLightSource() || blockState.drawType() == BlockDrawType::Multibox)
vertices[v].ambientOcclusion = 4;

if (blockState.drawType() == BlockDrawType::Liquid)
Expand Down
5 changes: 2 additions & 3 deletions source/client/world/mesh/LightUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*
* =====================================================================================
*/
#include "Config.hpp"
#include "LightUtils.hpp"

// Based on this article: https://0fps.net/2013/07/03/ambient-occlusion-for-minecraft-like-worlds/
Expand Down Expand Up @@ -63,7 +62,7 @@ u8 LightUtils::getAmbientOcclusion(s8f x, s8f y, s8f z,
u8 LightUtils::getLightForVertex(LightType lightType, s8f x, s8f y, s8f z,
const gk::Vector3<s8f> &offset,
const gk::Vector3<s8f> &normal,
const ChunkData &chunk)
const ChunkData &chunk, bool useAO)
{
gk::Vector3<s8f> minOffset{
(normal.x != 0) ? offset.x : s8f(0),
Expand Down Expand Up @@ -100,7 +99,7 @@ u8 LightUtils::getLightForVertex(LightType lightType, s8f x, s8f y, s8f z,

// If the chunk is initialized, add the light value to the total
// But only add dark blocks if AO is set on Smooth Lighting
if (lightValues[i] != -1 && (Config::ambientOcclusion == 2 || lightValues[i] != 0)) {
if (lightValues[i] != -1 && (useAO || lightValues[i] != 0)) {
total += (u8)lightValues[i];
++count;
}
Expand Down
2 changes: 1 addition & 1 deletion source/client/world/mesh/LightUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace LightUtils {

u8 getLightForVertex(LightType lightType, s8f x, s8f y, s8f z,
const gk::Vector3<s8f> &offset,
const gk::Vector3<s8f> &normal, const ChunkData &chunk);
const gk::Vector3<s8f> &normal, const ChunkData &chunk, bool useAO);
};

#endif // LIGHTUTILS_HPP_

0 comments on commit 19355e9

Please sign in to comment.