diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index c9ea5ef7..78b56104 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -2113,6 +2113,7 @@ Client uses non-rigid-body collidables for farther away entities (via client LOD Reorder main content draw calls to support non-OIT transparencies better Content debug supports rendering paths Rendering ai pathfinding paths +Simplify part of transvoxel algo diff --git a/src/main/java/electrosphere/renderer/meshgen/TransvoxelModelGeneration.java b/src/main/java/electrosphere/renderer/meshgen/TransvoxelModelGeneration.java index 793242f5..4adb004b 100644 --- a/src/main/java/electrosphere/renderer/meshgen/TransvoxelModelGeneration.java +++ b/src/main/java/electrosphere/renderer/meshgen/TransvoxelModelGeneration.java @@ -28,60 +28,60 @@ public class TransvoxelModelGeneration { /** * Number of ints required to store an element */ - static final int INTS_PER_ELEMENT = 1; + public static final int INTS_PER_ELEMENT = 1; /** * Number of elements per triangle */ - static final int ELEMENTS_PER_TRIANGLE = 3; + public static final int ELEMENTS_PER_TRIANGLE = 3; /** * Number of floats per vert */ - static final int FLOATS_PER_VERT = 3; + public static final int FLOATS_PER_VERT = 3; /** * Number of vertices per triangle */ - static final int VERTS_PER_TRIANGLE = ELEMENTS_PER_TRIANGLE; + public static final int VERTS_PER_TRIANGLE = ELEMENTS_PER_TRIANGLE; /** * Number of floats per UV */ - static final int FLOATS_PER_UV = 2; + public static final int FLOATS_PER_UV = 2; /** * The number of sampler indices per triangle */ - static final int SAMPLER_INDICES_PER_TRIANGLE = 3; + public static final int SAMPLER_INDICES_PER_TRIANGLE = 3; /** * The number of sampler values to store for each vertex */ - static final int SAMPLER_VALUES_PER_VERT = 3; + public static final int SAMPLER_VALUES_PER_VERT = 3; /** * Size of the vector pool */ - static final int VECTOR_POOL_SIZE = 13; + public static final int VECTOR_POOL_SIZE = 13; /** * Threshold of normal dot product */ - static final float NORMAL_DOT_THRESHOLD = 0.99f; + public static final float NORMAL_DOT_THRESHOLD = 0.99f; /** * The min dist to check */ - static final double MIN_DIST = 0.00001; + public static final double MIN_DIST = 0.00001; //this is the width of the transition cell //it should be between 0 and 1, exclusive //the higher the value, the more of the high resolution chunk we will see //the lower the value, the more of the low resolution chunk we will see - static final float TRANSITION_CELL_WIDTH = 0.5f; + public static final float TRANSITION_CELL_WIDTH = 0.5f; /** * The dimension of the array for the face generator. It must be 2 * + 1. The extra 1 is for the neighbor value @@ -98,7 +98,7 @@ public class TransvoxelModelGeneration { /** * A single generated triangle */ - static class Triangle { + private static class Triangle { //the indices int[] indices = new int[3]; //array of size 3 @@ -118,7 +118,7 @@ public class TransvoxelModelGeneration { /** * The grid cell currently being looked at */ - static class GridCell { + private static class GridCell { Vector3f[] points = new Vector3f[8]; //array of size 8 double[] val = new double[8]; //array of size 8 int[] atlasValues = new int[8]; //array of size 8 @@ -148,7 +148,7 @@ public class TransvoxelModelGeneration { /** * The transition grid cell currently being looked at */ - static class TransitionGridCell { + private static class TransitionGridCell { Vector3f[][] complexFacePoints = new Vector3f[3][3]; Vector3f[][] simpleFacePoints = new Vector3f[2][2]; float[][] complexFaceValues = new float[3][3]; @@ -205,9 +205,14 @@ public class TransvoxelModelGeneration { - //location of the sampler index data in the shader + /** + * location of the sampler index data in the shader + */ public static final int SAMPLER_INDEX_ATTRIB_LOC = 5; - //the ratio vectors of how much to pull from each texture + + /** + * the ratio vectors of how much to pull from each texture + */ public static final int SAMPLER_RATIO_ATTRIB_LOC = 6; @@ -234,7 +239,6 @@ public class TransvoxelModelGeneration { */ protected static int polygonize( GridCell grid, - double isolevel, List triangles, List samplerIndices, Map vertMap, @@ -251,6 +255,8 @@ public class TransvoxelModelGeneration { int ntriang; int cubeIndex = 0; + float isolevel = TerrainChunkModelGeneration.MIN_ISO_VALUE; + //essentially, because the iso level is 0, we can end up generating weird midpoints between 0 and negative values //in order to not actually generate triangles for these edge cases, the skip table is populated if the current edge is between 0 and a negative value //when storing triangles, all skip edges trigger the loop to skip to the next triangle set @@ -524,7 +530,6 @@ public class TransvoxelModelGeneration { */ protected static int polygonizeTransition( TransitionGridCell transitionCell, - double isolevel, List triangles, List samplerIndices, Map vertMap, @@ -537,6 +542,8 @@ public class TransvoxelModelGeneration { StringBuilder builder ){ + float isolevel = TerrainChunkModelGeneration.MIN_ISO_VALUE; + /** @@ -1277,7 +1284,7 @@ public class TransvoxelModelGeneration { chunkData.textureGrid[x+0][y+1][z+0], chunkData.textureGrid[x+0][y+1][z+1], chunkData.textureGrid[x+1][y+1][z+1], chunkData.textureGrid[x+1][y+1][z+0] ); //polygonize the current gridcell - TransvoxelModelGeneration.polygonize(currentCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); + TransvoxelModelGeneration.polygonize(currentCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); } } } @@ -1349,7 +1356,7 @@ public class TransvoxelModelGeneration { chunkData.xPositiveEdgeAtlas[(y+0)*2+0][(z+0)*2+0], chunkData.xPositiveEdgeAtlas[(y+1)*2+0][(z+0)*2+0], chunkData.xPositiveEdgeAtlas[(y+0)*2+0][(z+1)*2+0], chunkData.xPositiveEdgeAtlas[(y+1)*2+0][(z+1)*2+0] ); - TransvoxelModelGeneration.polygonizeTransition(currentTransitionCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, true, vertList, samplerIndex, builder); + TransvoxelModelGeneration.polygonizeTransition(currentTransitionCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, true, vertList, samplerIndex, builder); // //Generate the normal cell with half width @@ -1371,7 +1378,7 @@ public class TransvoxelModelGeneration { chunkData.textureGrid[x+0][y+1][z+0], chunkData.textureGrid[x+0][y+1][z+1], chunkData.xPositiveEdgeAtlas[(y+1)*2+0][(z+1)*2+0], chunkData.xPositiveEdgeAtlas[(y+1)*2+0][(z+0)*2+0] ); //polygonize the current gridcell - TransvoxelModelGeneration.polygonize(currentCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); + TransvoxelModelGeneration.polygonize(currentCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); } } } else { @@ -1396,7 +1403,7 @@ public class TransvoxelModelGeneration { chunkData.textureGrid[x+0][y+1][z+0], chunkData.textureGrid[x+0][y+1][z+1], chunkData.textureGrid[x+1][y+1][z+1], chunkData.textureGrid[x+1][y+1][z+0] ); //polygonize the current gridcell - TransvoxelModelGeneration.polygonize(currentCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); + TransvoxelModelGeneration.polygonize(currentCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); } } } @@ -1461,7 +1468,7 @@ public class TransvoxelModelGeneration { chunkData.xNegativeEdgeAtlas[(y+0)*2+0][(z+0)*2+0], chunkData.xNegativeEdgeAtlas[(y+1)*2+0][(z+0)*2+0], chunkData.xNegativeEdgeAtlas[(y+0)*2+0][(z+1)*2+0], chunkData.xNegativeEdgeAtlas[(y+1)*2+0][(z+1)*2+0] ); - TransvoxelModelGeneration.polygonizeTransition(currentTransitionCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, builder); + TransvoxelModelGeneration.polygonizeTransition(currentTransitionCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, builder); // //Generate the normal cell with half width @@ -1483,7 +1490,7 @@ public class TransvoxelModelGeneration { chunkData.xNegativeEdgeAtlas[(y+1)*2+0][(z+0)*2+0], chunkData.xNegativeEdgeAtlas[(y+1)*2+0][(z+1)*2+0], chunkData.textureGrid[x+1][y+1][z+1], chunkData.textureGrid[x+1][y+1][z+0] ); //polygonize the current gridcell - TransvoxelModelGeneration.polygonize(currentCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); + TransvoxelModelGeneration.polygonize(currentCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); } } } else { @@ -1508,7 +1515,7 @@ public class TransvoxelModelGeneration { chunkData.textureGrid[x+0][y+1][z+0], chunkData.textureGrid[x+0][y+1][z+1], chunkData.textureGrid[x+1][y+1][z+1], chunkData.textureGrid[x+1][y+1][z+0] ); //polygonize the current gridcell - TransvoxelModelGeneration.polygonize(currentCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); + TransvoxelModelGeneration.polygonize(currentCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); } } } @@ -1572,7 +1579,7 @@ public class TransvoxelModelGeneration { chunkData.yPositiveEdgeAtlas[(x+0)*2+0][(z+0)*2+0], chunkData.yPositiveEdgeAtlas[(x+1)*2+0][(z+0)*2+0], chunkData.yPositiveEdgeAtlas[(x+0)*2+0][(z+1)*2+0], chunkData.yPositiveEdgeAtlas[(x+1)*2+0][(z+1)*2+0] ); - TransvoxelModelGeneration.polygonizeTransition(currentTransitionCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, builder); + TransvoxelModelGeneration.polygonizeTransition(currentTransitionCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, builder); // //Generate the normal cell with half width @@ -1594,7 +1601,7 @@ public class TransvoxelModelGeneration { chunkData.yPositiveEdgeAtlas[(x+0)*2+0][(z+0)*2+0], chunkData.yPositiveEdgeAtlas[(x+0)*2+0][(z+1)*2+0], chunkData.yPositiveEdgeAtlas[(x+1)*2+0][(z+1)*2+0], chunkData.yPositiveEdgeAtlas[(x+1)*2+0][(z+0)*2+0] ); //polygonize the current gridcell - TransvoxelModelGeneration.polygonize(currentCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); + TransvoxelModelGeneration.polygonize(currentCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); } } } else { @@ -1619,7 +1626,7 @@ public class TransvoxelModelGeneration { chunkData.textureGrid[x+0][y+1][z+0], chunkData.textureGrid[x+0][y+1][z+1], chunkData.textureGrid[x+1][y+1][z+1], chunkData.textureGrid[x+1][y+1][z+0] ); //polygonize the current gridcell - TransvoxelModelGeneration.polygonize(currentCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); + TransvoxelModelGeneration.polygonize(currentCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); } } } @@ -1683,7 +1690,7 @@ public class TransvoxelModelGeneration { chunkData.yNegativeEdgeAtlas[(x+0)*2+0][(z+0)*2+0], chunkData.yNegativeEdgeAtlas[(x+1)*2+0][(z+0)*2+0], chunkData.yNegativeEdgeAtlas[(x+0)*2+0][(z+1)*2+0], chunkData.yNegativeEdgeAtlas[(x+1)*2+0][(z+1)*2+0] ); - TransvoxelModelGeneration.polygonizeTransition(currentTransitionCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, true, vertList, samplerIndex, builder); + TransvoxelModelGeneration.polygonizeTransition(currentTransitionCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, true, vertList, samplerIndex, builder); // //Generate the normal cell with half width @@ -1705,7 +1712,7 @@ public class TransvoxelModelGeneration { chunkData.yNegativeEdgeAtlas[(x+0)*2+0][(z+0)*2+0], chunkData.yNegativeEdgeAtlas[(x+0)*2+0][(z+1)*2+0], chunkData.yNegativeEdgeAtlas[(x+1)*2+0][(z+1)*2+0], chunkData.yNegativeEdgeAtlas[(x+1)*2+0][(z+0)*2+0] ); //polygonize the current gridcell - TransvoxelModelGeneration.polygonize(currentCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, true, vertList, samplerIndex, skip, builder); + TransvoxelModelGeneration.polygonize(currentCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, true, vertList, samplerIndex, skip, builder); } } } else { @@ -1730,7 +1737,7 @@ public class TransvoxelModelGeneration { chunkData.textureGrid[x+0][y+1][z+0], chunkData.textureGrid[x+0][y+1][z+1], chunkData.textureGrid[x+1][y+1][z+1], chunkData.textureGrid[x+1][y+1][z+0] ); //polygonize the current gridcell - TransvoxelModelGeneration.polygonize(currentCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); + TransvoxelModelGeneration.polygonize(currentCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); } } } @@ -1795,7 +1802,7 @@ public class TransvoxelModelGeneration { chunkData.zPositiveEdgeAtlas[(x+0)*2+0][(y+0)*2+0], chunkData.zPositiveEdgeAtlas[(x+0)*2+0][(y+1)*2+0], chunkData.zPositiveEdgeAtlas[(x+1)*2+0][(y+0)*2+0], chunkData.zPositiveEdgeAtlas[(x+1)*2+0][(y+1)*2+0] ); - TransvoxelModelGeneration.polygonizeTransition(currentTransitionCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, builder); + TransvoxelModelGeneration.polygonizeTransition(currentTransitionCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, builder); // //Generate the normal cell with half width @@ -1817,7 +1824,7 @@ public class TransvoxelModelGeneration { chunkData.textureGrid[x+0][y+1][z+0], chunkData.zPositiveEdgeAtlas[(x+0)*2+0][(y+1)*2+0], chunkData.zPositiveEdgeAtlas[(x+1)*2+0][(y+1)*2+0], chunkData.textureGrid[x+1][y+1][z+0] ); //polygonize the current gridcell - TransvoxelModelGeneration.polygonize(currentCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); + TransvoxelModelGeneration.polygonize(currentCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); } } } else { @@ -1842,7 +1849,7 @@ public class TransvoxelModelGeneration { chunkData.textureGrid[x+0][y+1][z+0], chunkData.textureGrid[x+0][y+1][z+1], chunkData.textureGrid[x+1][y+1][z+1], chunkData.textureGrid[x+1][y+1][z+0] ); //polygonize the current gridcell - TransvoxelModelGeneration.polygonize(currentCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); + TransvoxelModelGeneration.polygonize(currentCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); } } } @@ -1907,7 +1914,7 @@ public class TransvoxelModelGeneration { chunkData.zNegativeEdgeAtlas[(x+0)*2+0][(y+0)*2+0], chunkData.zNegativeEdgeAtlas[(x+0)*2+0][(y+1)*2+0], chunkData.zNegativeEdgeAtlas[(x+1)*2+0][(y+0)*2+0], chunkData.zNegativeEdgeAtlas[(x+1)*2+0][(y+1)*2+0] ); - TransvoxelModelGeneration.polygonizeTransition(currentTransitionCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, true, vertList, samplerIndex, builder); + TransvoxelModelGeneration.polygonizeTransition(currentTransitionCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, true, vertList, samplerIndex, builder); // //Generate the normal cell with half width @@ -1929,7 +1936,7 @@ public class TransvoxelModelGeneration { chunkData.textureGrid[x+0][y+1][z+1], chunkData.zNegativeEdgeAtlas[(x+0)*2+0][(y+1)*2+0], chunkData.zNegativeEdgeAtlas[(x+1)*2+0][(y+1)*2+0], chunkData.textureGrid[x+1][y+1][z+1] ); //polygonize the current gridcell - TransvoxelModelGeneration.polygonize(currentCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, true, vertList, samplerIndex, skip, builder); + TransvoxelModelGeneration.polygonize(currentCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, true, vertList, samplerIndex, skip, builder); } } } else { @@ -1954,7 +1961,7 @@ public class TransvoxelModelGeneration { chunkData.textureGrid[x+0][y+1][z+0], chunkData.textureGrid[x+0][y+1][z+1], chunkData.textureGrid[x+1][y+1][z+1], chunkData.textureGrid[x+1][y+1][z+0] ); //polygonize the current gridcell - TransvoxelModelGeneration.polygonize(currentCell, TerrainChunkModelGeneration.MIN_ISO_VALUE, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); + TransvoxelModelGeneration.polygonize(currentCell, triangles, samplerTriangles, vertMap, verts, normals, trianglesSharingVert, false, vertList, samplerIndex, skip, builder); } } }