Skip to content

Commit

Permalink
Reorient water quads according to the corner heights (CaffeineMC#2467)
Browse files Browse the repository at this point in the history
The seam is placed such that it touches either the highest or lowest corner.

Closes CaffeineMC#609
  • Loading branch information
douira authored May 10, 2024
1 parent 2cae1d0 commit fd18d0f
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,25 +215,37 @@ public void render(LevelSlice level, FluidState fluidState, BlockPos blockPos, B

quad.setSprite(sprite);

setVertex(quad, 0, 0.0f, northWestHeight, 0.0f, u1, v1);
setVertex(quad, 1, 0.0f, southWestHeight, 1.0F, u2, v2);
setVertex(quad, 2, 1.0F, southEastHeight, 1.0F, u3, v3);
setVertex(quad, 3, 1.0F, northEastHeight, 0.0f, u4, v4);

// top surface alignedness is calculated with a more relaxed epsilon
boolean aligned = isAlignedEquals(northEastHeight, northWestHeight)
&& isAlignedEquals(northWestHeight, southEastHeight)
&& isAlignedEquals(southEastHeight, southWestHeight)
&& isAlignedEquals(southWestHeight, northEastHeight);

boolean creaseNorthEastSouthWest = aligned
|| northEastHeight > northWestHeight && northEastHeight > southEastHeight
|| northEastHeight < northWestHeight && northEastHeight < southEastHeight
|| southWestHeight > northWestHeight && southWestHeight > southEastHeight
|| southWestHeight < northWestHeight && southWestHeight < southEastHeight;

if (creaseNorthEastSouthWest) {
setVertex(quad, 1, 0.0f, northWestHeight, 0.0f, u1, v1);
setVertex(quad, 2, 0.0f, southWestHeight, 1.0F, u2, v2);
setVertex(quad, 3, 1.0F, southEastHeight, 1.0F, u3, v3);
setVertex(quad, 0, 1.0F, northEastHeight, 0.0f, u4, v4);
} else {
setVertex(quad, 0, 0.0f, northWestHeight, 0.0f, u1, v1);
setVertex(quad, 1, 0.0f, southWestHeight, 1.0F, u2, v2);
setVertex(quad, 2, 1.0F, southEastHeight, 1.0F, u3, v3);
setVertex(quad, 3, 1.0F, northEastHeight, 0.0f, u4, v4);
}

this.updateQuad(quad, level, blockPos, lighter, Direction.UP, 1.0F, colorProvider, fluidState);
this.writeQuad(meshBuilder, collector, material, offset, quad, aligned ? ModelQuadFacing.POS_Y : ModelQuadFacing.UNASSIGNED, false);

if (fluidState.shouldRenderBackwardUpFace(level, this.scratchPos.set(posX, posY + 1, posZ))) {
this.writeQuad(meshBuilder, collector, material, offset, quad,
aligned ? ModelQuadFacing.NEG_Y : ModelQuadFacing.UNASSIGNED, true);
}

}

if (!sfDown) {
Expand Down Expand Up @@ -405,7 +417,7 @@ private void writeQuad(ChunkModelBuilder builder, TranslucentGeometryCollector c
var vertices = this.vertices;

for (int i = 0; i < 4; i++) {
var out = vertices[flip ? 3 - i : i];
var out = vertices[flip ? (3 - i + 1) & 0b11 : i];
out.x = offset.getX() + quad.getX(i);
out.y = offset.getY() + quad.getY(i);
out.z = offset.getZ() + quad.getZ(i);
Expand Down

0 comments on commit fd18d0f

Please sign in to comment.