Skip to content

Commit

Permalink
[BlockMesher] Finally fixed AO for multibox drawtype.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Jul 19, 2021
1 parent 19355e9 commit 19edee8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions resources/shaders/game.v.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ void main() {

if (ambientOcclusion != 4) {
const float aovalues[] = float[](0.4, 0.6, 0.8, 1.0);
v_ambientOcclusion = aovalues[int(ambientOcclusion)];
// v_ambientOcclusion = 0.4 + 0.2 * ambientOcclusion;
/* v_ambientOcclusion = aovalues[int(ambientOcclusion)]; */
v_ambientOcclusion = 0.4 + 0.2 * ambientOcclusion;
} else {
v_ambientOcclusion = 1.0;
}
Expand Down
21 changes: 20 additions & 1 deletion source/client/world/mesh/BlockMesher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,27 @@ void BlockMesher::addBlockFace(s8f x, s8f y, s8f z, s8f f, ChunkMeshBuildingJob
vertices[v].ambientOcclusion = getAmbientOcclusion(x, y, z, *neighbourOfs[v], normal, job.chunkData);
}

// Fix basic ambient occlusion for multibox draw type
if (blockState.drawType() == BlockDrawType::Multibox) {
float aoValues[nVertsPerFace] = {
vertices[0].ambientOcclusion,
vertices[1].ambientOcclusion,
vertices[2].ambientOcclusion,
vertices[3].ambientOcclusion
};

for (u8f v = 0; v < nVertsPerFace; ++v) {
float U = (v == 0 || v == 3) ? U0 : U1;
float V = 1.f - ((v >= 2) ? V0 : V1);

float a = gk::lerpf(aoValues[0], aoValues[1], U);
float b = gk::lerpf(aoValues[3], aoValues[2], U);
vertices[v].ambientOcclusion = gk::lerpf(a, b, V);
}
}

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

if (blockState.drawType() == BlockDrawType::Liquid)
Expand Down

0 comments on commit 19edee8

Please sign in to comment.