Skip to content

Commit

Permalink
fix: Don't set direction of diagonal faces (CaffeineMC#171)
Browse files Browse the repository at this point in the history
Prevents improper culling.
  • Loading branch information
mrmangohands committed Jan 10, 2021
1 parent d352852 commit c5405cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ public ChunkRenderBounds build(ChunkSectionPos origin) {
int z1 = origin.getMinZ() + leftBound(this.z);
int z2 = origin.getMinZ() + rightBound(this.z);

// Expand the bounding box by 8 blocks (half a chunk) in order to deal with diagonal surfaces
return new ChunkRenderBounds(
Math.max(x1, origin.getMinX()) - 8.0f,
Math.max(y1, origin.getMinY()) - 8.0f,
Math.max(z1, origin.getMinZ()) - 8.0f,
Math.max(x1, origin.getMinX()),
Math.max(y1, origin.getMinY()),
Math.max(z1, origin.getMinZ()),

Math.min(x2, origin.getMaxX()) + 8.0f,
Math.min(y2, origin.getMaxY()) + 8.0f,
Math.min(z2, origin.getMaxZ()) + 8.0f
Math.min(x2, origin.getMaxX()),
Math.min(y2, origin.getMaxY()),
Math.min(z2, origin.getMaxZ())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,13 @@ public boolean render(BlockRenderView world, FluidState fluidState, BlockPos pos
Vec3d velocity = fluidState.getVelocity(world, pos);

Sprite sprite;
ModelQuadFacing facing;
float u1, u2, u3, u4;
float v1, v2, v3, v4;

if (velocity.x == 0.0D && velocity.z == 0.0D) {
sprite = sprites[0];
facing = ModelQuadFacing.UP;
u1 = sprite.getFrameU(0.0D);
v1 = sprite.getFrameV(0.0D);
u2 = u1;
Expand All @@ -167,6 +169,7 @@ public boolean render(BlockRenderView world, FluidState fluidState, BlockPos pos
v4 = v1;
} else {
sprite = sprites[1];
facing = ModelQuadFacing.UNASSIGNED;
float dir = (float) MathHelper.atan2(velocity.z, velocity.x) - (1.5707964f);
float sin = MathHelper.sin(dir) * 0.25F;
float cos = MathHelper.cos(dir) * 0.25F;
Expand Down Expand Up @@ -203,15 +206,15 @@ public boolean render(BlockRenderView world, FluidState fluidState, BlockPos pos
this.setVertex(quad, 3, 1.0F, h4, 0.0f, u4, v4);

this.calculateQuadColors(quad, world, pos, lighter, Direction.UP, 1.0F, !lava);
this.flushQuad(buffers, quad, Direction.UP, false);
this.flushQuad(buffers, quad, facing, false);

if (fluidState.method_15756(world, this.scratchPos.set(posX, posY + 1, posZ))) {
this.setVertex(quad, 3, 0.0f, h1, 0.0f, u1, v1);
this.setVertex(quad, 2, 0.0f, h2, 1.0F, u2, v2);
this.setVertex(quad, 1, 1.0F, h3, 1.0F, u3, v3);
this.setVertex(quad, 0, 1.0F, h4, 0.0f, u4, v4);

this.flushQuad(buffers, quad, Direction.DOWN, true);
this.flushQuad(buffers, quad, ModelQuadFacing.DOWN, true);
}

rendered = true;
Expand All @@ -232,7 +235,7 @@ public boolean render(BlockRenderView world, FluidState fluidState, BlockPos pos
this.setVertex(quad, 3, 1.0F, yOffset, 1.0F, maxU, maxV);

this.calculateQuadColors(quad, world, pos, lighter, Direction.DOWN, 1.0F, !lava);
this.flushQuad(buffers, quad, Direction.DOWN, false);
this.flushQuad(buffers, quad, ModelQuadFacing.DOWN, false);

rendered = true;
}
Expand Down Expand Up @@ -332,15 +335,15 @@ public boolean render(BlockRenderView world, FluidState fluidState, BlockPos pos
float br = dir.getAxis() == Direction.Axis.Z ? 0.8F : 0.6F;

this.calculateQuadColors(quad, world, pos, lighter, dir, br, !lava);
this.flushQuad(buffers, quad, dir, false);
this.flushQuad(buffers, quad, ModelQuadFacing.fromDirection(dir), false);

if (sprite != this.waterOverlaySprite) {
this.setVertex(quad, 0, x1, c1, z1, u1, v1);
this.setVertex(quad, 1, x1, yOffset, z1, u1, v3);
this.setVertex(quad, 2, x2, yOffset, z2, u2, v3);
this.setVertex(quad, 3, x2, c2, z2, u2, v2);

this.flushQuad(buffers, quad, dir, true);
this.flushQuad(buffers, quad, ModelQuadFacing.fromDirection(dir), true);
}

rendered = true;
Expand All @@ -365,7 +368,7 @@ private void calculateQuadColors(ModelQuadView quad, BlockRenderView world, Blo
}
}

private void flushQuad(ChunkModelBuffers buffers, ModelQuadView quad, Direction dir, boolean flip) {
private void flushQuad(ChunkModelBuffers buffers, ModelQuadView quad, ModelQuadFacing facing, boolean flip) {
int vertexIdx, lightOrder;

if (flip) {
Expand All @@ -376,7 +379,7 @@ private void flushQuad(ChunkModelBuffers buffers, ModelQuadView quad, Direction
lightOrder = 1;
}

ModelVertexSink sink = buffers.getSink(ModelQuadFacing.fromDirection(dir));
ModelVertexSink sink = buffers.getSink(facing);
sink.ensureCapacity(4);

for (int i = 0; i < 4; i++) {
Expand Down

0 comments on commit c5405cc

Please sign in to comment.