From fd18d0f01ed20fca178b567afe8c09b6841e9587 Mon Sep 17 00:00:00 2001 From: douira Date: Fri, 10 May 2024 16:43:50 +0200 Subject: [PATCH] Reorient water quads according to the corner heights (#2467) The seam is placed such that it touches either the highest or lowest corner. Closes #609 --- .../pipeline/DefaultFluidRenderer.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/DefaultFluidRenderer.java b/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/DefaultFluidRenderer.java index 213903a6a1..9fe94aae16 100644 --- a/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/DefaultFluidRenderer.java +++ b/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/DefaultFluidRenderer.java @@ -215,17 +215,30 @@ 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); @@ -233,7 +246,6 @@ && isAlignedEquals(southEastHeight, southWestHeight) this.writeQuad(meshBuilder, collector, material, offset, quad, aligned ? ModelQuadFacing.NEG_Y : ModelQuadFacing.UNASSIGNED, true); } - } if (!sfDown) { @@ -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);