diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/makamys/neodymium/renderer/ChunkMesh.java | 14 | ||||
-rw-r--r-- | src/main/java/makamys/neodymium/renderer/MeshQuad.java | 8 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java index 971c6f2..de14867 100644 --- a/src/main/java/makamys/neodymium/renderer/ChunkMesh.java +++ b/src/main/java/makamys/neodymium/renderer/ChunkMesh.java @@ -204,6 +204,20 @@ public class ChunkMesh extends Mesh { } private static void simplifyPlane(List<MeshQuad> planeQuads) { + // Exclude quads from merging if they have identical vertex positions to another quad. + // Workaround for z-fighting issue that arises when merging fancy grass and the overlay quad + // is a different dimension than the base quad. + for(int i = 0; i < planeQuads.size(); i++) { + MeshQuad a = planeQuads.get(i); + for(int j = i + 1; j < planeQuads.size(); j++) { + MeshQuad b = planeQuads.get(j); + if(a.isPosEqual(b)) { + a.noMerge = true; + b.noMerge = true; + } + } + } + MeshQuad lastQuad = null; // Pass 1: merge quads to create rows for(MeshQuad quad : planeQuads) { diff --git a/src/main/java/makamys/neodymium/renderer/MeshQuad.java b/src/main/java/makamys/neodymium/renderer/MeshQuad.java index 581e6f3..45ea73b 100644 --- a/src/main/java/makamys/neodymium/renderer/MeshQuad.java +++ b/src/main/java/makamys/neodymium/renderer/MeshQuad.java @@ -2,6 +2,7 @@ package makamys.neodymium.renderer; import java.io.DataOutputStream; import java.io.IOException; +import java.util.Arrays; import java.util.Comparator; import java.util.Locale; import java.util.Map; @@ -46,6 +47,7 @@ public class MeshQuad { public int[] cs = new int[4]; // TODO normals? public boolean deleted; + public boolean noMerge; public Plane plane; public int offset; @@ -195,6 +197,8 @@ public class MeshQuad { } public void tryToMerge(MeshQuad o) { + if(noMerge || o.noMerge) return; + if(isTranslatedCopyOf(o, true)) { int numVerticesTouching = 0; boolean[] verticesTouching = new boolean[4]; @@ -329,4 +333,8 @@ public class MeshQuad { XZ, YZ } + + public boolean isPosEqual(MeshQuad b) { + return Arrays.equals(xs, b.xs) && Arrays.equals(ys, b.ys) && Arrays.equals(zs, b.zs); + } } |