aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2022-06-19 23:39:43 +0200
committermakamys <makamys@outlook.com>2022-06-19 23:39:43 +0200
commit3a55acf92313068e710700bf55f337bbdea337fc (patch)
tree9d1ba349871ff6c884ea2e43bd5bd8e9f43707b1
parente57b4e2bad040bc8a2621065e1626201221614a2 (diff)
downloadNeodymium-3a55acf92313068e710700bf55f337bbdea337fc.tar.gz
Neodymium-3a55acf92313068e710700bf55f337bbdea337fc.tar.bz2
Neodymium-3a55acf92313068e710700bf55f337bbdea337fc.zip
Add workaround for fancy grass z-fighting
This only increases quad count from 780 KQ to 792 KQ on the complex savanna scene.
-rw-r--r--src/main/java/makamys/neodymium/renderer/ChunkMesh.java14
-rw-r--r--src/main/java/makamys/neodymium/renderer/MeshQuad.java8
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);
+ }
}