Implement near and far fog for LODs
This commit is contained in:
@@ -4,19 +4,32 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import com.backsun.lod.util.fog.FogDistance;
|
||||
|
||||
import net.minecraft.client.renderer.GLAllocation;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
|
||||
public class BuildBufferThread implements Callable<ByteBuffer>
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 02-13-2021
|
||||
*/
|
||||
public class BuildBufferThread implements Callable<NearFarBuffer>
|
||||
{
|
||||
public ByteBuffer buffer;
|
||||
public ByteBuffer nearBuffer;
|
||||
public ByteBuffer farBuffer;
|
||||
public FogDistance distanceMode;
|
||||
public AxisAlignedBB[][] lods;
|
||||
public Color[][] colors;
|
||||
|
||||
private int lodStartX = 0;
|
||||
private int lodStartZ = 0;
|
||||
private int start = 0;
|
||||
private int end = -1;
|
||||
|
||||
@@ -35,9 +48,9 @@ public class BuildBufferThread implements Callable<ByteBuffer>
|
||||
vertexFormatElement = vertexFormat.getElement(vertexFormatIndex);
|
||||
}
|
||||
|
||||
BuildBufferThread(ByteBuffer newByteBuffer, AxisAlignedBB[][] newLods, Color[][] newColors, int threadNumber, int totalThreads)
|
||||
BuildBufferThread(ByteBuffer newNearByteBuffer, ByteBuffer newFarByteBuffer, AxisAlignedBB[][] newLods, Color[][] newColors, FogDistance newDistanceMode, Vec3i newLodStartCoordinate, int threadNumber, int totalThreads)
|
||||
{
|
||||
setNewData(newByteBuffer, newLods, newColors, threadNumber, totalThreads);
|
||||
setNewData(newNearByteBuffer, newFarByteBuffer, distanceMode, newLodStartCoordinate, newLods, newColors, threadNumber, totalThreads);
|
||||
|
||||
vertexCount = 0;
|
||||
vertexFormat = DefaultVertexFormats.POSITION_COLOR;
|
||||
@@ -45,12 +58,14 @@ public class BuildBufferThread implements Callable<ByteBuffer>
|
||||
vertexFormatElement = vertexFormat.getElement(vertexFormatIndex);
|
||||
}
|
||||
|
||||
public void setNewData(ByteBuffer newByteBuffer, AxisAlignedBB[][] newLods, Color[][] newColors, int threadNumber, int totalThreads)
|
||||
public void setNewData(ByteBuffer newNearByteBuffer, ByteBuffer newFarByteBuffer, FogDistance newDistanceMode, Vec3i newlodStartCoordinate, AxisAlignedBB[][] newLods, Color[][] newColors, int threadNumber, int totalThreads)
|
||||
{
|
||||
vertexCount = 0;
|
||||
vertexFormatIndex = 0;
|
||||
|
||||
buffer = newByteBuffer;
|
||||
nearBuffer = newNearByteBuffer;
|
||||
farBuffer = newFarByteBuffer;
|
||||
distanceMode = newDistanceMode;
|
||||
lods = newLods;
|
||||
colors = newColors;
|
||||
|
||||
@@ -58,19 +73,26 @@ public class BuildBufferThread implements Callable<ByteBuffer>
|
||||
int rowsToRender = numbChunksWide / totalThreads;
|
||||
start = threadNumber * rowsToRender;
|
||||
end = (threadNumber + 1) * rowsToRender;
|
||||
|
||||
lodStartX = newlodStartCoordinate.getX();
|
||||
lodStartZ = newlodStartCoordinate.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer call()
|
||||
public NearFarBuffer call()
|
||||
{
|
||||
int numbChunksWide = lods.length;
|
||||
|
||||
ByteBuffer currentBuffer;
|
||||
AxisAlignedBB bb;
|
||||
int red;
|
||||
int green;
|
||||
int blue;
|
||||
int alpha;
|
||||
|
||||
int chunkX;
|
||||
int chunkZ;
|
||||
|
||||
// x axis
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
@@ -99,84 +121,97 @@ public class BuildBufferThread implements Callable<ByteBuffer>
|
||||
blue = colors[i][j].getBlue();
|
||||
alpha = colors[i][j].getAlpha();
|
||||
|
||||
// choose which buffer to add these LODs too
|
||||
if (distanceMode == FogDistance.BOTH)
|
||||
{
|
||||
if (RenderUtil.isCoordinateInNearFogArea(i, j, numbChunksWide / 2))
|
||||
currentBuffer = nearBuffer;
|
||||
else
|
||||
currentBuffer = farBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentBuffer = nearBuffer;
|
||||
}
|
||||
|
||||
|
||||
if (bb.minY != bb.maxY)
|
||||
{
|
||||
// top (facing up)
|
||||
addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.maxY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.maxY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.maxY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.maxY, bb.minZ, red, green, blue, alpha);
|
||||
// bottom (facing down)
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
|
||||
// south (facing -Z)
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.maxY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.maxY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
// north (facing +Z)
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.maxY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.maxY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
|
||||
// west (facing -X)
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.maxY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.maxY, bb.minZ, red, green, blue, alpha);
|
||||
// east (facing +X)
|
||||
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.maxY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.maxY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
// render this LOD as one block thick
|
||||
|
||||
// top (facing up)
|
||||
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
// bottom (facing down)
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
|
||||
// south (facing -Z)
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
// north (facing +Z)
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
|
||||
// west (facing -X)
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.minX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
// east (facing +X)
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY+1, bb.minZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY+1, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY, bb.maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(currentBuffer, bb.maxX, bb.minY, bb.minZ, red, green, blue, alpha);
|
||||
}
|
||||
|
||||
} // z axis
|
||||
} // x axis
|
||||
|
||||
return buffer;
|
||||
return new NearFarBuffer(nearBuffer, farBuffer);
|
||||
}
|
||||
|
||||
private void addPosAndColor(ByteBuffer buffer, double x, double y, double z, int red, int green, int blue, int alpha)
|
||||
@@ -289,16 +324,16 @@ public class BuildBufferThread implements Callable<ByteBuffer>
|
||||
private void growBuffer(int p_181670_1_)
|
||||
{
|
||||
//if (MathHelper.roundUp(p_181670_1_, 4) / 4 > this.rawIntBuffer.remaining() || this.vertexCount * this.vertexFormat.getNextOffset() + p_181670_1_ > this.byteBuffer.capacity())
|
||||
if (this.vertexCount * this.vertexFormat.getNextOffset() + p_181670_1_ > buffer.capacity())
|
||||
if (this.vertexCount * this.vertexFormat.getNextOffset() + p_181670_1_ > nearBuffer.capacity())
|
||||
{
|
||||
int i = buffer.capacity();
|
||||
int i = nearBuffer.capacity();
|
||||
int j = i + MathHelper.roundUp(p_181670_1_, 2097152);
|
||||
// int k = this.rawIntBuffer.position();
|
||||
ByteBuffer directBytebuffer = GLAllocation.createDirectByteBuffer(j);
|
||||
buffer.position(0);
|
||||
directBytebuffer.put(buffer);
|
||||
nearBuffer.position(0);
|
||||
directBytebuffer.put(nearBuffer);
|
||||
directBytebuffer.rewind();
|
||||
buffer = directBytebuffer;
|
||||
nearBuffer = directBytebuffer;
|
||||
// this.rawFloatBuffer = buffer.asFloatBuffer().asReadOnlyBuffer();
|
||||
// this.rawIntBuffer = buffer.asIntBuffer();
|
||||
// this.rawIntBuffer.position(k);
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.backsun.lod.objects.LodDimension;
|
||||
import com.backsun.lod.util.ReflectionHandler;
|
||||
import com.backsun.lod.util.enums.ColorDirection;
|
||||
import com.backsun.lod.util.enums.LodLocation;
|
||||
import com.backsun.lod.util.fog.FogDistanceMode;
|
||||
import com.backsun.lod.util.fog.FogDistance;
|
||||
import com.backsun.lod.util.fog.FogQuality;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -31,10 +31,11 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
|
||||
/**
|
||||
* @author James Seibel
|
||||
* @version 2-10-2021
|
||||
* @version 2-13-2021
|
||||
*/
|
||||
public class LodRenderer
|
||||
{
|
||||
@@ -44,9 +45,9 @@ public class LodRenderer
|
||||
private float farPlaneDistance;
|
||||
// make sure this is an even number, or else it won't align with the chunk grid
|
||||
/** this is the total width of the LODs (I.E the diameter, not the radius) */
|
||||
public static final int VIEW_DISTANCE_MULTIPLIER = 12;
|
||||
public static final int LOD_WIDTH = 16;
|
||||
public static final int MINECRAFT_CHUNK_WIDTH = 16;
|
||||
public static final int VIEW_DISTANCE_MULTIPLIER = 12; // TODO rename and split into 2 variables
|
||||
public static final int LOD_WIDTH = 16; // TODO remove and replace with the LodChunk variable
|
||||
public static final int MINECRAFT_CHUNK_WIDTH = 16; // TODO remove and replace with the LodChunk variable
|
||||
|
||||
private Tessellator tessellator;
|
||||
private BufferBuilder bufferBuilder;
|
||||
@@ -67,7 +68,8 @@ public class LodRenderer
|
||||
/** How many threads should be used for building the render buffer. */
|
||||
private int numbBufferThreads = maxThreads;
|
||||
private ArrayList<BuildBufferThread> bufferThreads = new ArrayList<BuildBufferThread>();
|
||||
private volatile ByteBuffer[] buffers = new ByteBuffer[maxThreads];
|
||||
private volatile ByteBuffer[] nearBuffers = new ByteBuffer[maxThreads];
|
||||
private volatile ByteBuffer[] farBuffers = new ByteBuffer[maxThreads];
|
||||
private ExecutorService threadPool = Executors.newFixedThreadPool(maxThreads);
|
||||
/*
|
||||
* this is the maximum number of bytes a buffer
|
||||
@@ -325,13 +327,15 @@ public class LodRenderer
|
||||
|
||||
mc.mcProfiler.endStartSection("LOD build buffer");
|
||||
if (regen)
|
||||
generateLodBuffers(lodArray, colorArray);
|
||||
generateLodBuffers(lodArray, colorArray, FogDistance.BOTH, new Vec3i(startX, 0, startZ));
|
||||
|
||||
mc.mcProfiler.endStartSection("LOD draw setup");
|
||||
setupFog(FogDistanceMode.NEAR, reflectionHandler.getFogQuality());
|
||||
sendLodsToGpuAndDraw();
|
||||
|
||||
setupFog(FogDistance.NEAR, reflectionHandler.getFogQuality());
|
||||
sendLodsToGpuAndDraw(nearBuffers);
|
||||
|
||||
mc.mcProfiler.endStartSection("LOD draw setup");
|
||||
setupFog(FogDistance.FAR, reflectionHandler.getFogQuality());
|
||||
sendLodsToGpuAndDraw(farBuffers);
|
||||
|
||||
|
||||
|
||||
@@ -383,34 +387,44 @@ public class LodRenderer
|
||||
* @param lods bounding boxes to draw
|
||||
* @param colors color of each box to draw
|
||||
*/
|
||||
private void generateLodBuffers(AxisAlignedBB[][] lods, Color[][] colors)
|
||||
private void generateLodBuffers(AxisAlignedBB[][] lods, Color[][] colors, FogDistance fogDistance, Vec3i lodStartCoordinate)
|
||||
{
|
||||
List<Future<ByteBuffer>> bufferFutures = new ArrayList<>();
|
||||
bufferMaxCapacity = (lods.length * lods.length * (6 * 4 * ((3 * 4) + (4 * 4)))) / numbBufferThreads;
|
||||
List<Future<NearFarBuffer>> bufferFutures = new ArrayList<>();
|
||||
bufferMaxCapacity = (lods.length * lods.length * (6 * 4 * ((3 * 4) + (4 * 4)))) / numbBufferThreads; // TODO this should change based on whether we are using near/far or both fog settings
|
||||
|
||||
for(int i = 0; i < numbBufferThreads; i++)
|
||||
for(int i = 0; i < maxThreads; i++)
|
||||
{
|
||||
if (buffers[i] == null || previousChunkRenderDistance != mc.gameSettings.renderDistanceChunks)
|
||||
if (nearBuffers[i] == null || previousChunkRenderDistance != mc.gameSettings.renderDistanceChunks)
|
||||
{
|
||||
buffers[i] = ByteBuffer.allocateDirect(bufferMaxCapacity);
|
||||
buffers[i].order(ByteOrder.LITTLE_ENDIAN);
|
||||
nearBuffers[i] = ByteBuffer.allocateDirect(bufferMaxCapacity);
|
||||
nearBuffers[i].order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
farBuffers[i] = ByteBuffer.allocateDirect(bufferMaxCapacity);
|
||||
farBuffers[i].order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
clearBytes = new byte[bufferMaxCapacity];
|
||||
}
|
||||
|
||||
if (regen)
|
||||
{
|
||||
// this is the best way I could find to
|
||||
// overwrite the old data
|
||||
// (which needs to be done otherwise the old
|
||||
// (which needs to be done otherwise old
|
||||
// LODs may be drawn)
|
||||
buffers[i].clear();
|
||||
buffers[i].put(clearBytes);
|
||||
buffers[i].clear();
|
||||
nearBuffers[i].clear();
|
||||
nearBuffers[i].put(clearBytes);
|
||||
nearBuffers[i].clear();
|
||||
|
||||
farBuffers[i].clear();
|
||||
farBuffers[i].put(clearBytes);
|
||||
farBuffers[i].clear();
|
||||
}
|
||||
|
||||
int pos = bufferBuilder.getByteBuffer().position();
|
||||
buffers[i].position(pos);
|
||||
nearBuffers[i].position(pos);
|
||||
farBuffers[i].position(pos);
|
||||
|
||||
bufferThreads.get(i).setNewData(buffers[i], lods, colors, i, numbBufferThreads);
|
||||
bufferThreads.get(i).setNewData(nearBuffers[i], farBuffers[i], fogDistance, lodStartCoordinate, lods, colors, i, numbBufferThreads);
|
||||
}
|
||||
|
||||
try
|
||||
@@ -427,7 +441,8 @@ public class LodRenderer
|
||||
{
|
||||
try
|
||||
{
|
||||
buffers[i] = bufferFutures.get(i).get();
|
||||
nearBuffers[i] = bufferFutures.get(i).get().nearBuffer;
|
||||
farBuffers[i] = bufferFutures.get(i).get().farBuffer;
|
||||
}
|
||||
catch(CancellationException | ExecutionException| InterruptedException e)
|
||||
{
|
||||
@@ -438,7 +453,7 @@ public class LodRenderer
|
||||
|
||||
}
|
||||
|
||||
private void sendLodsToGpuAndDraw()
|
||||
private void sendLodsToGpuAndDraw(ByteBuffer[] buffers)
|
||||
{
|
||||
for(int i = 0; i < numbBufferThreads; i++)
|
||||
{
|
||||
@@ -467,20 +482,25 @@ public class LodRenderer
|
||||
// Setup Functions //
|
||||
//=================//
|
||||
|
||||
private void setupFog(FogDistanceMode fogMode, FogQuality fogQuality)
|
||||
private void setupFog(FogDistance fogDistance, FogQuality fogQuality)
|
||||
{
|
||||
if(fogQuality == FogQuality.OFF)
|
||||
{
|
||||
GlStateManager.disableFog();
|
||||
return;
|
||||
}
|
||||
|
||||
if(fogDistance == FogDistance.BOTH)
|
||||
{
|
||||
throw new IllegalArgumentException("setupFog only accepts NEAR or FAR fog distances.");
|
||||
}
|
||||
|
||||
// the multipliers are percentages
|
||||
// of the regular view distance.
|
||||
|
||||
// TODO add the ability to change the fogDistanceMode
|
||||
// in the mod settings
|
||||
if(fogMode == FogDistanceMode.NEAR)
|
||||
if(fogDistance == FogDistance.NEAR)
|
||||
{
|
||||
// the reason that I wrote fogEnd then fogStart backwards
|
||||
// is because we are using fog backwards to how
|
||||
@@ -489,8 +509,8 @@ public class LodRenderer
|
||||
|
||||
if (fogQuality == FogQuality.FANCY || fogQuality == FogQuality.UNKNOWN)
|
||||
{
|
||||
GlStateManager.setFogEnd(farPlaneDistance * 2.0f);
|
||||
GlStateManager.setFogStart(farPlaneDistance * 2.5f);
|
||||
GlStateManager.setFogEnd(farPlaneDistance * 0.3f * (VIEW_DISTANCE_MULTIPLIER * 0.5f));
|
||||
GlStateManager.setFogStart(farPlaneDistance * 0.35f * (VIEW_DISTANCE_MULTIPLIER * 0.5f));
|
||||
}
|
||||
else if(fogQuality == FogQuality.FAST)
|
||||
{
|
||||
@@ -502,17 +522,17 @@ public class LodRenderer
|
||||
GlStateManager.setFogStart(farPlaneDistance * 3.5f);
|
||||
}
|
||||
}
|
||||
else if(fogMode == FogDistanceMode.FAR)
|
||||
else if(fogDistance == FogDistance.FAR)
|
||||
{
|
||||
if (fogQuality == FogQuality.FANCY || fogQuality == FogQuality.UNKNOWN)
|
||||
{
|
||||
GlStateManager.setFogStart(farPlaneDistance * 0.5f * VIEW_DISTANCE_MULTIPLIER / 2.0f);
|
||||
GlStateManager.setFogEnd(farPlaneDistance * 1.0f * VIEW_DISTANCE_MULTIPLIER / 2.0f);
|
||||
GlStateManager.setFogStart(farPlaneDistance * 0.78f * (VIEW_DISTANCE_MULTIPLIER * 0.5f)); // TODO rename to view_distance_radius
|
||||
GlStateManager.setFogEnd(farPlaneDistance * 1.0f * (VIEW_DISTANCE_MULTIPLIER * 0.5f));
|
||||
}
|
||||
else if(fogQuality == FogQuality.FAST)
|
||||
{
|
||||
GlStateManager.setFogStart(farPlaneDistance * 0.5f * VIEW_DISTANCE_MULTIPLIER / 2.0f);
|
||||
GlStateManager.setFogEnd(farPlaneDistance * 0.8f * VIEW_DISTANCE_MULTIPLIER / 2.0f);
|
||||
GlStateManager.setFogStart(farPlaneDistance * 0.5f * VIEW_DISTANCE_MULTIPLIER);
|
||||
GlStateManager.setFogEnd(farPlaneDistance * 0.8f * VIEW_DISTANCE_MULTIPLIER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -583,8 +603,11 @@ public class LodRenderer
|
||||
|
||||
for(int i = 0; i < maxThreads; i++)
|
||||
{
|
||||
buffers[i] = ByteBuffer.allocateDirect(bufferMaxCapacity);
|
||||
buffers[i].order(ByteOrder.LITTLE_ENDIAN);
|
||||
nearBuffers[i] = ByteBuffer.allocateDirect(bufferMaxCapacity);
|
||||
nearBuffers[i].order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
farBuffers[i] = ByteBuffer.allocateDirect(bufferMaxCapacity);
|
||||
farBuffers[i].order(ByteOrder.LITTLE_ENDIAN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.backsun.lod.renderer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* This object is just a replacement for an array
|
||||
* to make things easier to understand in the LodRenderer
|
||||
* and BuildBufferThread.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 02-13-2021
|
||||
*/
|
||||
public class NearFarBuffer
|
||||
{
|
||||
public ByteBuffer nearBuffer;
|
||||
|
||||
public ByteBuffer farBuffer;
|
||||
|
||||
|
||||
NearFarBuffer(ByteBuffer newNearBuffer, ByteBuffer newFarBuffer)
|
||||
{
|
||||
nearBuffer = newNearBuffer;
|
||||
farBuffer = newFarBuffer;
|
||||
}
|
||||
}
|
||||
@@ -7,22 +7,39 @@ import net.minecraft.client.Minecraft;
|
||||
* to be used in the rendering process.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2-10-2021
|
||||
* @version 2-13-2021
|
||||
*/
|
||||
public class RenderUtil
|
||||
{
|
||||
/**
|
||||
* Returns if the given coordinate is in the loaded area of the world.
|
||||
* @param middle the center of the loaded world
|
||||
* @param centerCoordinate the center of the loaded world
|
||||
*/
|
||||
public static boolean isCoordinateInLoadedArea(int x, int z, int middle)
|
||||
public static boolean isCoordinateInLoadedArea(int i, int j, int centerCoordinate)
|
||||
{
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
return (x >= middle - mc.gameSettings.renderDistanceChunks
|
||||
&& x <= middle + mc.gameSettings.renderDistanceChunks)
|
||||
return (i >= centerCoordinate - mc.gameSettings.renderDistanceChunks
|
||||
&& i <= centerCoordinate + mc.gameSettings.renderDistanceChunks)
|
||||
&&
|
||||
(z >= middle - mc.gameSettings.renderDistanceChunks
|
||||
&& z <= middle + mc.gameSettings.renderDistanceChunks);
|
||||
(j >= centerCoordinate - mc.gameSettings.renderDistanceChunks
|
||||
&& j <= centerCoordinate + mc.gameSettings.renderDistanceChunks);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find the coordinates that are in the center half of the given
|
||||
* 2D matrix, starting at (0,0) and going to (2 * lodRadius, 2 * lodRadius).
|
||||
*/
|
||||
public static boolean isCoordinateInNearFogArea(int i, int j, int lodRadius)
|
||||
{
|
||||
int halfRadius = lodRadius / 2;
|
||||
|
||||
return (i >= lodRadius - halfRadius
|
||||
&& i <= lodRadius + halfRadius)
|
||||
&&
|
||||
(j >= lodRadius - halfRadius
|
||||
&& j <= lodRadius + halfRadius);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ package com.backsun.lod.util.fog;
|
||||
* @author James Seibel
|
||||
* @version 01-27-2021
|
||||
*/
|
||||
public enum FogDistanceMode
|
||||
public enum FogDistance
|
||||
{
|
||||
/** valid for both fast and fancy qualities. */
|
||||
NEAR,
|
||||
Reference in New Issue
Block a user