Fixed culling

This commit is contained in:
Leonardo
2021-09-20 11:35:20 +02:00
parent 3e634c082a
commit 01b9a3f3b0
2 changed files with 57 additions and 44 deletions
@@ -294,48 +294,45 @@ public class LodBufferBuilder
}
// skip any chunks that Minecraft is going to render
try
for (Direction direction : Box.ADJ_DIRECTIONS)
{
for (Direction direction : Box.ADJ_DIRECTIONS)
{
xAdj = posX + direction.getNormal().getX();
zAdj = posZ + direction.getNormal().getZ();
chunkXdist = LevelPosUtil.getChunkPos(detailLevel, xAdj) - playerChunkPos.x;
chunkZdist = LevelPosUtil.getChunkPos(detailLevel, zAdj) - playerChunkPos.z;
boolean performFaceCulling = false;
if (performFaceCulling
&& posToRender.contains(detailLevel, xAdj, zAdj)
&& (gameChunkRenderDistance < Math.abs(chunkXdist)
xAdj = posX + direction.getNormal().getX();
zAdj = posZ + direction.getNormal().getZ();
chunkXdist = LevelPosUtil.getChunkPos(detailLevel, xAdj) - playerChunkPos.x;
chunkZdist = LevelPosUtil.getChunkPos(detailLevel, zAdj) - playerChunkPos.z;
boolean performFaceCulling = true;
if (performFaceCulling
&& posToRender.contains(detailLevel, xAdj, zAdj)
/*&& (gameChunkRenderDistance < Math.abs(chunkXdist)
|| gameChunkRenderDistance < Math.abs(chunkZdist)
|| !vanillaRenderedChunks[chunkXdist + gameChunkRenderDistance + 1][chunkZdist + gameChunkRenderDistance + 1]))
{
if (!adjData.containsKey(direction) || adjData.get(direction)==null)
adjData.put(direction, new long[maxVerticalData]);
for (int verticalIndex = 0; verticalIndex < lodDim.getMaxVerticalData(detailLevel, xAdj, zAdj); verticalIndex++)
adjData.get(direction)[verticalIndex] = lodDim.getData(detailLevel, xAdj, zAdj, verticalIndex);
} else
{
adjData.put(direction, null);
}
}
long data;
for (int verticalIndex = 0; verticalIndex < lodDim.getMaxVerticalData(detailLevel, posX, posZ); verticalIndex++)
|| !vanillaRenderedChunks[chunkXdist + gameChunkRenderDistance + 1][chunkZdist + gameChunkRenderDistance + 1])*/)
{
data = lodDim.getData(detailLevel, posX, posZ, verticalIndex);
if (DataPointUtil.isItVoid(data) || !DataPointUtil.doesItExist(data))
break;
LodConfig.CLIENT.graphics.lodTemplate.get().template.addLodToBuffer(currentBuffer, playerBlockPosRounded, data, adjData,
detailLevel, posX, posZ, boxCache[xR][zR], renderer.previousDebugMode, renderer.lightMap);
if (!adjData.containsKey(direction) || adjData.get(direction) == null)
adjData.put(direction, new long[maxVerticalData]);
for (int verticalIndex = 0; verticalIndex < lodDim.getMaxVerticalData(detailLevel, xAdj, zAdj); verticalIndex++)
{
long data = lodDim.getData(detailLevel, xAdj, zAdj, verticalIndex);
if(!DataPointUtil.isItVoid(data) && DataPointUtil.doesItExist(data))
System.out.println(DataPointUtil.toString(data));
adjData.get(direction)[verticalIndex] = data;
}
} else
{
adjData.put(direction, null);
}
} catch (ArrayIndexOutOfBoundsException e)
{
e.printStackTrace();
return false;
}
long data;
for (int verticalIndex = 0; verticalIndex < lodDim.getMaxVerticalData(detailLevel, posX, posZ); verticalIndex++)
{
data = lodDim.getData(detailLevel, posX, posZ, verticalIndex);
if (DataPointUtil.isItVoid(data) || !DataPointUtil.doesItExist(data))
break;
LodConfig.CLIENT.graphics.lodTemplate.get().template.addLodToBuffer(currentBuffer, playerBlockPosRounded, data, adjData,
detailLevel, posX, posZ, boxCache[xR][zR], renderer.previousDebugMode, renderer.lightMap);
}
} // for pos to in list to render
// the thread executed successfully
return true;
@@ -7,11 +7,14 @@ import com.seibel.lod.config.LodConfig;
import com.seibel.lod.enums.DebugMode;
import com.seibel.lod.util.ColorUtil;
import com.seibel.lod.util.DataPointUtil;
import com.seibel.lod.util.DetailDistanceUtil;
import com.seibel.lod.wrappers.MinecraftWrapper;
import net.minecraft.util.Direction;
import net.minecraft.util.math.vector.Vector3d;
import javax.xml.crypto.Data;
public class Box
{
@@ -100,6 +103,7 @@ public class Box
}};
public int[][] box;
public long[] order;
public Map<Direction, int[]> colorMap;
public int color;
public Map<Direction, int[][]> adjHeightAndDepth;
@@ -109,7 +113,7 @@ public class Box
public Box()
{
box = new int[2][3];
//order = new long[32];
order = new long[DetailDistanceUtil.getMaxVerticalData(0)];
colorMap = new HashMap<Direction, int[]>()
{{
put(Direction.UP, new int[1]);
@@ -172,6 +176,8 @@ public class Box
colorMap.get(direction)[0] = 0;
}
for(int i = 0; i < order.length; i++)
order[i] = DataPointUtil.EMPTY_DATA;
for (Direction direction : ADJ_DIRECTIONS)
{
if(isCulled(direction)){
@@ -234,27 +240,37 @@ public class Box
//We order the adj list
/**TODO remove this if the order is maintained naturally*/
/*
order[0] = 0;
int count = 0;
for (int i = 0; i < dataPoint.length; i++)
{
int j = i - 1;
while (j >= 0 && DataPointUtil.getHeight(order[j]) > DataPointUtil.getHeight(dataPoint[i])) {
if(DataPointUtil.isItVoid(dataPoint[i]) || !DataPointUtil.doesItExist(dataPoint[i]))
{
continue;
}
while (j >= 0 && DataPointUtil.getHeight(order[j]) < DataPointUtil.getHeight(dataPoint[i]))
{
order[j + 1] = order[j];
j = j - 1;
}
order[j + 1] = dataPoint[i];
}*/
count++;
}
int i;
int faceToDraw = 0;
boolean firstFace = true;
boolean toFinish = false;
for (i = dataPoint.length - 1; i >= 0; i--)
/*for (i = dataPoint.length - 1; i >= 0; i--)
{
long singleDataPoint = dataPoint[i];
height = DataPointUtil.getHeight(singleDataPoint);
depth = DataPointUtil.getDepth(singleDataPoint);
long singleDataPoint = dataPoint[i];*/
long singleAdjDataPoint;
for (i = 0; i < count; i++)
{
singleAdjDataPoint = order[i];
height = DataPointUtil.getHeight(singleAdjDataPoint);
depth = DataPointUtil.getDepth(singleAdjDataPoint);
if (depth > maxY)
{//the adj data is higher than the current data