Skip to content

Commit

Permalink
Optimise SemiCompact Rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
thr3343 committed Nov 20, 2023
1 parent dcff864 commit e395109
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/vulkanmod/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Config {
public boolean guiOptimizations = false;
public int advCulling = 2;
public boolean indirectDraw = false;
public boolean uniqueOpaqueLayer = true;
public boolean uniqueOpaqueLayer = false;
public boolean entityCulling = true;

private static Path path;
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/net/vulkanmod/render/chunk/DrawBuffers.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.vulkanmod.render.chunk;

import net.vulkanmod.Initializer;
import net.vulkanmod.render.chunk.build.UploadBuffer;
import net.vulkanmod.render.chunk.util.StaticQueue;
import net.vulkanmod.render.vertex.TerrainRenderType;
Expand Down Expand Up @@ -39,11 +38,11 @@ public DrawBuffers(int index, Vector3i origin) {

this.index = index;
this.origin = origin;
COMPACT_RENDER_TYPES.forEach(t -> sectionQueues.put(t, new StaticQueue<>(512)));
getActiveLayers().forEach(t -> sectionQueues.put(t, new StaticQueue<>(512)));
}

public void allocateBuffers() {
COMPACT_RENDER_TYPES.forEach(t -> areaBufferTypes.put(t, new AreaBuffer(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, t.initialSize, VERTEX_SIZE)));
getActiveLayers().forEach(t -> areaBufferTypes.put(t, new AreaBuffer(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, t.initialSize, VERTEX_SIZE)));
this.indexBuffer = new AreaBuffer(VK_BUFFER_USAGE_INDEX_BUFFER_BIT, 1000000, INDEX_SIZE);

this.allocated = true;
Expand Down Expand Up @@ -151,7 +150,7 @@ public void buildDrawBatchesIndirect(IndirectBuffer indirectBuffer, TerrainRende

long ptr = bufferPtr + (drawCount * 20L);
MemoryUtil.memPutInt(ptr, drawParameters.indexCount);
MemoryUtil.memPutInt(ptr + 4, drawParameters.indexCount != 0 ? 1 : 0);
MemoryUtil.memPutInt(ptr + 4, 1);
MemoryUtil.memPutInt(ptr + 8, drawParameters.firstIndex);
// MemoryUtil.memPutInt(ptr + 12, drawParameters.vertexBufferSegment.getOffset() / VERTEX_SIZE);
MemoryUtil.memPutInt(ptr + 12, drawParameters.vertexOffset);
Expand Down Expand Up @@ -240,7 +239,7 @@ public void buildDrawBatchesDirect(TerrainRenderType terrainRenderType, double c

for (var iterator = this.sectionQueues.get(terrainRenderType).iterator(isTranslucent); iterator.hasNext(); ) {
final DrawParameters drawParameters = iterator.next();
vkCmdDrawIndexed(commandBuffer, drawParameters.indexCount, drawParameters.indexCount != 0 ? 1 : 0, drawParameters.firstIndex, drawParameters.vertexOffset, drawParameters.baseInstance);
vkCmdDrawIndexed(commandBuffer, drawParameters.indexCount, 1, drawParameters.firstIndex, drawParameters.vertexOffset, drawParameters.baseInstance);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ else if(terrainRenderType.equals(TRANSLUCENT))
p.push("draw batches");

final int currentFrame = Renderer.getCurrentFrame();
if((TerrainRenderType.COMPACT_RENDER_TYPES).contains(terrainRenderType)) {
if((Initializer.CONFIG.uniqueOpaqueLayer ? COMPACT_RENDER_TYPES : SEMI_COMPACT_RENDER_TYPES).contains(terrainRenderType)) {


Renderer.getInstance().bindGraphicsPipeline(terrainShader);
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/net/vulkanmod/render/chunk/build/ChunkTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,17 @@ private CompileResults compile(float camX, float camY, float camZ, ThreadBuilder

private TerrainRenderType compactRenderTypes(TerrainRenderType renderType) {

if (renderType != TRANSLUCENT) {
if (renderType != TRIPWIRE) {
return CUTOUT_MIPPED;
} else
return TRANSLUCENT;
if(Initializer.CONFIG.uniqueOpaqueLayer) {
if (renderType != TRANSLUCENT) {
return renderType != TRIPWIRE ? CUTOUT_MIPPED : TRANSLUCENT;
}
}
else {
return switch (renderType) {
case SOLID, CUTOUT_MIPPED -> CUTOUT_MIPPED;
case CUTOUT -> CUTOUT;
default -> TRANSLUCENT;
};
}

return renderType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package net.vulkanmod.render.vertex;

import net.minecraft.client.renderer.RenderType;
import net.vulkanmod.Initializer;
import net.vulkanmod.vulkan.VRenderSystem;

import java.util.EnumSet;

public enum TerrainRenderType {
SOLID(RenderType.solid(), 0.0f, 2500000),
CUTOUT_MIPPED(RenderType.cutoutMipped(), 0.5f, 2500000),
CUTOUT(RenderType.cutout(), 0.1f, 2500000),
CUTOUT(RenderType.cutout(), 0.1f, 100000),
TRANSLUCENT(RenderType.translucent(), 0.0f, 1000000),
TRIPWIRE(RenderType.tripwire(), 0.1f, 1000000);

public static final TerrainRenderType[] VALUES = TerrainRenderType.values();

public static final EnumSet<TerrainRenderType> COMPACT_RENDER_TYPES = EnumSet.of(CUTOUT_MIPPED, TRANSLUCENT);
public static final EnumSet<TerrainRenderType> SEMI_COMPACT_RENDER_TYPES = EnumSet.of(CUTOUT_MIPPED, CUTOUT, TRANSLUCENT);

final float alphaCutout;
public final int maxSize; //Not sure if this should be changed to UINT16_INDEX_MAX * vertexSize
Expand All @@ -26,6 +28,10 @@ public enum TerrainRenderType {
this.initialSize = initialSize;
}

public static EnumSet<TerrainRenderType> getActiveLayers() {
return Initializer.CONFIG.uniqueOpaqueLayer ? COMPACT_RENDER_TYPES : SEMI_COMPACT_RENDER_TYPES;
}

public void setCutoutUniform() {
VRenderSystem.alphaCutout = this.alphaCutout;
}
Expand Down

0 comments on commit e395109

Please sign in to comment.