diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/FluidRenderer.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/FluidRenderer.java index ce6a3af6c2..2120e8248f 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/FluidRenderer.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/FluidRenderer.java @@ -44,6 +44,7 @@ public class FluidRenderer { // TODO: allow this to be changed by vertex format // TODO: move fluid rendering to a separate render pass and control glPolygonOffset and glDepthFunc to fix this properly private static final float EPSILON = 0.001f; + private static final float ALIGNED_EQUALS_EPSILON = 0.011f; private final BlockPos.Mutable scratchPos = new BlockPos.Mutable(); private final MutableFloat scratchHeight = new MutableFloat(0); @@ -96,6 +97,10 @@ private boolean isSideExposed(BlockRenderView world, int x, int y, int z, Direct return true; } + private static boolean isAlignedEquals(float a, float b) { + return Math.abs(a - b) <= ALIGNED_EQUALS_EPSILON; + } + public void render(WorldSlice world, FluidState fluidState, BlockPos blockPos, BlockPos offset, ChunkBuildBuffers buffers) { var material = DefaultMaterials.forFluidState(fluidState); var meshBuilder = buffers.get(material); @@ -215,10 +220,30 @@ public void render(WorldSlice world, 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, world, blockPos, lighter, Direction.UP, 1.0F, colorProvider, fluidState); this.writeQuad(meshBuilder, material, offset, quad, facing, false); @@ -228,7 +253,6 @@ public void render(WorldSlice world, FluidState fluidState, BlockPos blockPos, B ModelQuadFacing.NEG_Y, true); } - } if (!sfDown) { @@ -363,7 +387,7 @@ private ColorProvider getColorProvider(Fluid fluid, FluidRenderHandl if (override != null) { return override; } - + return DefaultColorProviders.adapt(handler); } @@ -397,7 +421,7 @@ private void writeQuad(ChunkModelBuilder builder, Material material, BlockPos of 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);