aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2021-06-02 03:43:42 +0200
committermakamys <makamys@outlook.com>2021-06-02 03:43:42 +0200
commit7efc1268d83511653a015611faeb4a5ead0354be (patch)
tree24b3dc27add8e2c9d720f8e0fd26acb1d8f31f0c /src/main/java/makamys
parent0f5e4212aac09eac64a48064a0f44176736a157c (diff)
downloadNeodymium-7efc1268d83511653a015611faeb4a5ead0354be.tar.gz
Neodymium-7efc1268d83511653a015611faeb4a5ead0354be.tar.bz2
Neodymium-7efc1268d83511653a015611faeb4a5ead0354be.zip
Reduce simple mesh tricount
Diffstat (limited to 'src/main/java/makamys')
-rw-r--r--src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java150
1 files changed, 119 insertions, 31 deletions
diff --git a/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java b/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java
index 5d9526c..07bb084 100644
--- a/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java
+++ b/src/main/java/makamys/lodmod/renderer/SimpleChunkMesh.java
@@ -56,6 +56,8 @@ public class SimpleChunkMesh extends Mesh {
SimpleChunkMesh pass1 = new SimpleChunkMesh(target.xPosition, target.zPosition, divisions * divisions * 25, 0);
SimpleChunkMesh pass2 = new SimpleChunkMesh(target.xPosition, target.zPosition, divisions * divisions * 25, 1);
+ SimpleChunkMeshBuilder builder = new SimpleChunkMeshBuilder();
+
for(int divX = 0; divX < divisions; divX++) {
for(int divZ = 0; divZ < divisions; divZ++) {
IIcon icon = null;
@@ -124,10 +126,11 @@ public class SimpleChunkMesh extends Mesh {
color = (0xFF << 24) | ((color >> 16 & 0xFF) << 0) | ((color >> 8 & 0xFF) << 8) | ((color >> 0 & 0xFF) << 16);
if(biome.getFloatTemperature(worldX, y, worldZ) < 0.15f) {
- pass1.addCube(worldX, worldY + 0.2f, worldZ, size, size, 1f, Blocks.snow_layer.getIcon(1, 0), 0xFFFFFFFF, brightnessMult);
- pass1.addCube(worldX, worldY - 0.8f, worldZ, size, size, Math.min(LODMod.maxSimpleMeshHeight, worldY + 1 - 0.8f), icon, color, brightnessMult);
+
+ builder.addCube(divX, divZ, worldY + 0.2f, 1f, Blocks.snow_layer.getIcon(1, 0), 0xFFFFFFFF, brightnessMult);
+ builder.addCube(divX, divZ, worldY - 0.8f, -1, icon, color, brightnessMult);
} else {
- pass1.addCube(worldX, worldY, worldZ, size, size, Math.min(LODMod.maxSimpleMeshHeight, worldY + 1), icon, color, brightnessMult);
+ builder.addCube(divX, divZ, worldY, -1, icon, color, brightnessMult);
}
@@ -137,12 +140,81 @@ public class SimpleChunkMesh extends Mesh {
}
}
+ builder.render(pass1, target.xPosition, target.zPosition);
+
pass1.finish();
pass2.finish();
return Arrays.asList(new SimpleChunkMesh[] {pass1.quadCount != 0 ? pass1 : null, pass2.quadCount != 0 ? pass2 : null});
}
+ private static class SimpleChunkMeshBuilder {
+ int maxIconsPerColumn = 2;
+ float[][][] heights = new float[divisions][divisions][maxIconsPerColumn];
+ float[][][] depths = new float[divisions][divisions][maxIconsPerColumn];
+ IIcon[][][] icons = new IIcon[divisions][divisions][maxIconsPerColumn];
+ int[][][] colors = new int[divisions][divisions][maxIconsPerColumn];
+ float[][][] brightnessMults = new float[divisions][divisions][maxIconsPerColumn];
+
+ public void addCube(int x, int z, float height, float depth, IIcon icon, int color, float brightnessMult) {
+ IIcon[] iconz = icons[x][z];
+ int i = iconz[0] == null ? 0 : 1;
+ if(iconz[0] != null && iconz[1] != null) {
+ throw new IllegalStateException("Too many icons in column");
+ }
+
+ heights[x][z][i] = height;
+ depths[x][z][i] = depth;
+ icons[x][z][i] = icon;
+ colors[x][z][i] = color;
+ brightnessMults[x][z][i] = brightnessMult;
+ }
+
+ public void render(SimpleChunkMesh mesh, int chunkX, int chunkZ) {
+ float size = 16 / divisions;
+
+ for(int x = 0; x < divisions; x++) {
+ for(int z = 0; z < divisions; z++) {
+ float worldX = chunkX * 16 + x * size;
+ float worldZ = chunkZ * 16 + z * size;
+ for(int i = 0; i < maxIconsPerColumn; i++) {
+ IIcon icon = icons[x][z][i];
+ if(icon != null) {
+ float height = heights[x][z][i];
+ float depthValue = depths[x][z][i];
+ float depth = depthValue == -1 ? height : depthValue;
+ int color = colors[x][z][i];
+ float brightnessMult = brightnessMults[x][z][i];
+
+ if(i == 0) {
+ mesh.addFaceYPos(worldX, height, worldZ, size, size, icon, color, brightnessMult);
+ }
+ float heightX0 = x > 0 ? heights[x - 1][z][0] : 0;
+ if(heightX0 < height) {
+ mesh.addFaceX2(worldX, height, worldZ, Math.min(depth, height - heightX0), size, icon, color, brightnessMult);
+ }
+
+ float heightX1 = x < divisions - 1 ? heights[x + 1][z][0] : 0;
+ if(heightX1 < height) {
+ mesh.addFaceX1(worldX + size, height, worldZ, Math.min(depth, height - heightX1), size, icon, color, brightnessMult);
+ }
+
+ float heightZ0 = z > 0 ? heights[x][z - 1][0] : 0;
+ if(heightZ0 < height) {
+ mesh.addFaceZ1(worldX, height, worldZ, size, Math.min(depth, height - heightZ0), icon, color, brightnessMult);
+ }
+
+ float heightZ1 = z < divisions - 1 ? heights[x][z + 1][0] : 0;
+ if(heightZ1 < height) {
+ mesh.addFaceZ2(worldX, height, worldZ + size, size, Math.min(depth, height - heightZ1), icon, color, brightnessMult);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
public SimpleChunkMesh(int x, int z, int maxQuads, int pass) {
this.x = x;
this.y = 64;
@@ -165,36 +237,52 @@ public class SimpleChunkMesh extends Mesh {
private void addCube(float x, float y, float z, float sizeX, float sizeZ, float sizeY, IIcon icon, int color, float brightnessMult) {
addFaceYPos(x, y, z, sizeX, sizeZ, icon, color, brightnessMult);
- addFace(
- x + 0, y - sizeY, z + 0,
- x + 0, y + 0, z + 0,
- x + sizeX, y + 0, z + 0,
- x + sizeX, y - sizeY, z + 0,
- icon, color, (int)(200 * brightnessMult)
- );
- addFace(
- x + sizeX, y - sizeY, z + sizeZ,
- x + sizeX, y + 0, z + sizeZ,
- x + 0, y + 0, z + sizeZ,
- x + 0, y - sizeY, z + sizeZ,
- icon, color, (int)(200 * brightnessMult)
- );
- addFace(
- x + sizeX, y - sizeY, z + 0,
- x + sizeX, y + 0, z + 0,
- x + sizeX, y + 0, z + sizeZ,
- x + sizeX, y - sizeY, z + sizeZ,
- icon, color, (int)(160 * brightnessMult)
- );
- addFace(
- x + 0, y - sizeY, z + sizeZ,
- x + 0, y + 0, z + sizeZ,
- x + 0, y + 0, z + 0,
- x + 0, y - sizeY, z + 0,
- icon, color, (int)(160 * brightnessMult)
- );
+ addFaceZ1(x, y, z, sizeX, sizeY, icon, color, brightnessMult);
+ addFaceZ2(x, y, z + sizeZ, sizeX, sizeY, icon, color, brightnessMult);
+ addFaceX1(x + sizeX, y, z, sizeX, sizeY, icon, color, brightnessMult);
+ addFaceX2(x, y, z, sizeX, sizeY, icon, color, brightnessMult);
+ }
+
+ private void addFaceZ1(float x, float y, float z, float sizeX, float sizeY, IIcon icon, int color, float brightnessMult) {
+ addFace(
+ x + 0, y - sizeY, z + 0,
+ x + 0, y + 0, z + 0,
+ x + sizeX, y + 0, z + 0,
+ x + sizeX, y - sizeY, z + 0,
+ icon, color, (int)(200 * brightnessMult)
+ );
}
+ private void addFaceZ2(float x, float y, float z, float sizeX, float sizeY, IIcon icon, int color, float brightnessMult) {
+ addFace(
+ x + sizeX, y - sizeY, z,
+ x + sizeX, y + 0, z,
+ x + 0, y + 0, z,
+ x + 0, y - sizeY, z,
+ icon, color, (int)(200 * brightnessMult)
+ );
+ }
+
+ private void addFaceX1(float x, float y, float z, float sizeY, float sizeZ, IIcon icon, int color, float brightnessMult) {
+ addFace(
+ x, y - sizeY, z + 0,
+ x, y + 0, z + 0,
+ x, y + 0, z + sizeZ,
+ x, y - sizeY, z + sizeZ,
+ icon, color, (int)(160 * brightnessMult)
+ );
+ }
+
+ private void addFaceX2(float x, float y, float z, float sizeY, float sizeZ, IIcon icon, int color, float brightnessMult) {
+ addFace(
+ x + 0, y - sizeY, z + sizeZ,
+ x + 0, y + 0, z + sizeZ,
+ x + 0, y + 0, z + 0,
+ x + 0, y - sizeY, z + 0,
+ icon, color, (int)(160 * brightnessMult)
+ );
+ }
+
private void addFaceYPos(float x, float y, float z, float sizeX, float sizeZ, IIcon icon, int color, float brightnessMult) {
addFace(
x + 0, y + 0, z + 0,