From c02959efee7a81e5c0c97863a9296a1648cb352c Mon Sep 17 00:00:00 2001 From: austin Date: Mon, 4 Nov 2024 22:28:59 -0500 Subject: [PATCH] voxel fixes --- docs/src/progress/renderertodo.md | 7 +++++++ .../terrain/cells/ClientDrawCellManager.java | 6 +++--- .../meshgen/TerrainChunkModelGeneration.java | 14 ++++++++------ .../meshgen/TransvoxelModelGeneration.java | 18 ++++++++++++++++-- .../terrain/generation/heightmap/HillsGen.java | 2 +- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 0af83474..01793aa2 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -931,6 +931,13 @@ Refactoring generator code Optimizations Fix transvoxel xnzn edge generation +(11/04/2024) +Major draw cell optimizations +Fix normals calculation in transvoxel rasterizer +Fix draw cell LOD joining bug +Fix draw cell bounding sphere calculation +Hill Gen tweaks + # TODO diff --git a/src/main/java/electrosphere/client/terrain/cells/ClientDrawCellManager.java b/src/main/java/electrosphere/client/terrain/cells/ClientDrawCellManager.java index f41d2212..92ab7eb1 100644 --- a/src/main/java/electrosphere/client/terrain/cells/ClientDrawCellManager.java +++ b/src/main/java/electrosphere/client/terrain/cells/ClientDrawCellManager.java @@ -28,12 +28,12 @@ public class ClientDrawCellManager { /** * The distance to draw at full resolution */ - public static final double FULL_RES_DIST = 5 * ServerTerrainChunk.CHUNK_DIMENSION; + public static final double FULL_RES_DIST = 12 * ServerTerrainChunk.CHUNK_DIMENSION; /** * The distance for half resolution */ - public static final double HALF_RES_DIST = 15 * ServerTerrainChunk.CHUNK_DIMENSION; + public static final double HALF_RES_DIST = 16 * ServerTerrainChunk.CHUNK_DIMENSION; /** * The octree holding all the chunks to evaluate @@ -355,7 +355,7 @@ public class ClientDrawCellManager { !node.isLeaf() && ( ( - node.getLevel() == this.chunkTree.getMaxLevel() && + node.getLevel() == this.chunkTree.getMaxLevel() - 1 && this.getMinDistance(pos, node) > FULL_RES_DIST ) || diff --git a/src/main/java/electrosphere/renderer/meshgen/TerrainChunkModelGeneration.java b/src/main/java/electrosphere/renderer/meshgen/TerrainChunkModelGeneration.java index 880065ec..ced73d9f 100644 --- a/src/main/java/electrosphere/renderer/meshgen/TerrainChunkModelGeneration.java +++ b/src/main/java/electrosphere/renderer/meshgen/TerrainChunkModelGeneration.java @@ -892,13 +892,15 @@ public class TerrainChunkModelGeneration { //bounding sphere logic - float halfChunk = ServerTerrainChunk.CHUNK_DIMENSION / 2.0f; mesh.updateBoundingSphere( - halfChunk, - halfChunk, - halfChunk, - (float)Math.sqrt(halfChunk * halfChunk + halfChunk * halfChunk + halfChunk * halfChunk) - ); + ServerTerrainChunk.CHUNK_DIMENSION, + ServerTerrainChunk.CHUNK_DIMENSION, + ServerTerrainChunk.CHUNK_DIMENSION, + (float)Math.sqrt( + ServerTerrainChunk.CHUNK_DIMENSION * ServerTerrainChunk.CHUNK_DIMENSION + + ServerTerrainChunk.CHUNK_DIMENSION * ServerTerrainChunk.CHUNK_DIMENSION + + ServerTerrainChunk.CHUNK_DIMENSION * ServerTerrainChunk.CHUNK_DIMENSION + )); diff --git a/src/main/java/electrosphere/renderer/meshgen/TransvoxelModelGeneration.java b/src/main/java/electrosphere/renderer/meshgen/TransvoxelModelGeneration.java index 9608f7f3..529dd01d 100644 --- a/src/main/java/electrosphere/renderer/meshgen/TransvoxelModelGeneration.java +++ b/src/main/java/electrosphere/renderer/meshgen/TransvoxelModelGeneration.java @@ -375,7 +375,7 @@ public class TransvoxelModelGeneration { * @param vertMap The vert map * @param verts The list of verts * @param normals The normal map - * @param trianglesSharingVert The indices of triangles sharing verts + * @param trianglesSharingVert The indices of triangles sharing verts -- Used for making sure normals are pointing correctly * @return The number of triangles created */ protected static int polygonizeTransition( @@ -491,7 +491,8 @@ public class TransvoxelModelGeneration { //the class of transition cell - short cellClass = (short)(transitionCellClass[caseIndex]); + short cellClass = transitionCellClass[caseIndex]; + int windingOrder = (cellClass >>> 7) & 1; LoggerInterface.loggerRenderer.DEBUG("Cell class: " + cellClass + " " + String.format("0x%02X", cellClass)); @@ -700,6 +701,11 @@ public class TransvoxelModelGeneration { int index1 = getVertIndex(vert1,vertMap,verts); int index2 = getVertIndex(vert2,vertMap,verts); + if(windingOrder == 1){ + index0 = getVertIndex(vert2,vertMap,verts); + index2 = getVertIndex(vert0,vertMap,verts); + } + //add 0's to normals until it matches vert count while(trianglesSharingVert.size() < verts.size()){ trianglesSharingVert.add(0); @@ -978,6 +984,14 @@ public class TransvoxelModelGeneration { } } + /** + * Mixes two normals given a proportion value for each + * @param normal0 The first vector + * @param proportion0 The proportion of the first vector + * @param normal1 The second vector + * @param proportion1 The proportion of the second vector + * @return The mixed vector + */ private static Vector3f averageNormals(Vector3f normal0, float proportion0, Vector3f normal1, float proportion1){ Vector3f rVal = new Vector3f(normal0); rVal = rVal.mul(proportion0).add(new Vector3f(normal1).mul(proportion1)); diff --git a/src/main/java/electrosphere/server/terrain/generation/heightmap/HillsGen.java b/src/main/java/electrosphere/server/terrain/generation/heightmap/HillsGen.java index f1cce43a..3cb97bf8 100644 --- a/src/main/java/electrosphere/server/terrain/generation/heightmap/HillsGen.java +++ b/src/main/java/electrosphere/server/terrain/generation/heightmap/HillsGen.java @@ -16,7 +16,7 @@ public class HillsGen implements HeightmapGenerator { /** * Scales the input positions */ - static final float POSITION_SCALE = 0.005f; + static final float POSITION_SCALE = 0.01f; /** * Scales the output height