diff --git a/src/main/java/net/vulkanmod/config/Config.java b/src/main/java/net/vulkanmod/config/Config.java index b265f6d58..313d40455 100644 --- a/src/main/java/net/vulkanmod/config/Config.java +++ b/src/main/java/net/vulkanmod/config/Config.java @@ -21,7 +21,7 @@ public class Config { public int advCulling = 2; public boolean indirectDraw = false; - public boolean uniqueOpaqueLayer = true; + public boolean earlyZ = false; public boolean entityCulling = true; public int device = -1; diff --git a/src/main/java/net/vulkanmod/config/option/Options.java b/src/main/java/net/vulkanmod/config/option/Options.java index b84b7d3a2..e51eba3e1 100644 --- a/src/main/java/net/vulkanmod/config/option/Options.java +++ b/src/main/java/net/vulkanmod/config/option/Options.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.platform.Window; import net.minecraft.client.*; +import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.network.chat.Component; import net.vulkanmod.Initializer; import net.vulkanmod.config.Config; @@ -249,13 +250,14 @@ public static OptionBlock[] getOptimizationOpts() { value -> config.entityCulling = value, () -> config.entityCulling) .setTooltip(Component.translatable("vulkanmod.options.entityCulling.tooltip")), - new SwitchOption(Component.translatable("vulkanmod.options.uniqueOpaqueLayer"), + new SwitchOption(Component.translatable("vulkanmod.options.earlyZ"), value -> { - config.uniqueOpaqueLayer = value; + config.earlyZ = value; +// ItemBlockRenderTypes.setFancy(!value); minecraft.levelRenderer.allChanged(); }, - () -> config.uniqueOpaqueLayer) - .setTooltip(Component.translatable("vulkanmod.options.uniqueOpaqueLayer.tooltip")), + () -> config.earlyZ) + .setTooltip(Component.translatable("vulkanmod.options.earlyZ.tooltip")), new SwitchOption(Component.translatable("vulkanmod.options.indirectDraw"), value -> config.indirectDraw = value, () -> config.indirectDraw) diff --git a/src/main/java/net/vulkanmod/render/PipelineManager.java b/src/main/java/net/vulkanmod/render/PipelineManager.java index 52b037fdb..313bed94d 100644 --- a/src/main/java/net/vulkanmod/render/PipelineManager.java +++ b/src/main/java/net/vulkanmod/render/PipelineManager.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.vertex.VertexFormat; import net.minecraft.client.renderer.RenderType; +import net.vulkanmod.Initializer; import net.vulkanmod.render.chunk.build.thread.ThreadBuilderPack; import net.vulkanmod.render.vertex.CustomVertexFormat; import net.vulkanmod.render.vertex.TerrainRenderType; @@ -33,7 +34,11 @@ public static void init() { } public static void setDefaultShader() { - setShaderGetter(renderType -> renderType == TerrainRenderType.TRANSLUCENT ? terrainShaderEarlyZ : terrainShader); + setShaderGetter(renderType -> switch (renderType) { + case SOLID, TRANSLUCENT, TRIPWIRE -> terrainShaderEarlyZ; + case CUTOUT_MIPPED -> Initializer.CONFIG.earlyZ ? terrainShaderEarlyZ : terrainShader; + case CUTOUT -> terrainShader; + }); } private static void createBasicPipelines() { diff --git a/src/main/java/net/vulkanmod/render/chunk/WorldRenderer.java b/src/main/java/net/vulkanmod/render/chunk/WorldRenderer.java index 61c1430a3..51bda2ef9 100644 --- a/src/main/java/net/vulkanmod/render/chunk/WorldRenderer.java +++ b/src/main/java/net/vulkanmod/render/chunk/WorldRenderer.java @@ -48,6 +48,9 @@ import java.util.*; +import static org.lwjgl.opengl.GL11C.GL_LEQUAL; +import static org.lwjgl.opengl.GL11C.GL_LESS; + public class WorldRenderer { private static WorldRenderer INSTANCE; @@ -307,11 +310,12 @@ public void renderSectionLayer(RenderType renderType, PoseStack poseStack, doubl this.minecraft.getProfiler().popPush(() -> "render_" + renderType); final boolean isTranslucent = terrainRenderType == TerrainRenderType.TRANSLUCENT; + final boolean earlyZ = Initializer.CONFIG.earlyZ; final boolean indirectDraw = Initializer.CONFIG.indirectDraw; VRenderSystem.applyMVP(poseStack.last().pose(), projection); VRenderSystem.setPrimitiveTopologyGL(GL11.GL_TRIANGLES); - + VRenderSystem.depthFunc(earlyZ ? GL_LESS : GL_LEQUAL); Renderer renderer = Renderer.getInstance(); GraphicsPipeline pipeline = PipelineManager.getTerrainShader(terrainRenderType); renderer.bindGraphicsPipeline(pipeline); @@ -322,8 +326,9 @@ public void renderSectionLayer(RenderType renderType, PoseStack poseStack, doubl Renderer.getDrawer().bindIndexBuffer(Renderer.getCommandBuffer(), indexBuffer); int currentFrame = Renderer.getCurrentFrame(); - Set allowedRenderTypes = Initializer.CONFIG.uniqueOpaqueLayer ? TerrainRenderType.COMPACT_RENDER_TYPES : TerrainRenderType.SEMI_COMPACT_RENDER_TYPES; + Set allowedRenderTypes = Initializer.CONFIG.earlyZ ? TerrainRenderType.SEMI_COMPACT_RENDER_TYPES : TerrainRenderType.COMPACT_RENDER_TYPES; if (allowedRenderTypes.contains(terrainRenderType)) { + terrainRenderType.setCutoutUniform(); for (Iterator iterator = this.sectionGraph.getChunkAreaQueue().iterator(isTranslucent); iterator.hasNext(); ) { diff --git a/src/main/java/net/vulkanmod/render/chunk/build/task/BuildTask.java b/src/main/java/net/vulkanmod/render/chunk/build/task/BuildTask.java index 4a3cd1ce2..6ac53509f 100644 --- a/src/main/java/net/vulkanmod/render/chunk/build/task/BuildTask.java +++ b/src/main/java/net/vulkanmod/render/chunk/build/task/BuildTask.java @@ -173,15 +173,15 @@ private TerrainBufferBuilder getBufferBuilder(ThreadBuilderPack bufferBuilders, } private TerrainRenderType compactRenderTypes(TerrainRenderType renderType) { - if (Initializer.CONFIG.uniqueOpaqueLayer) { + if (Initializer.CONFIG.earlyZ) { renderType = switch (renderType) { - case SOLID, CUTOUT, CUTOUT_MIPPED -> TerrainRenderType.CUTOUT_MIPPED; + case SOLID, CUTOUT_MIPPED -> TerrainRenderType.CUTOUT_MIPPED; + case CUTOUT -> TerrainRenderType.CUTOUT; case TRANSLUCENT, TRIPWIRE -> TerrainRenderType.TRANSLUCENT; }; } else { renderType = switch (renderType) { - case SOLID, CUTOUT_MIPPED -> TerrainRenderType.CUTOUT_MIPPED; - case CUTOUT -> TerrainRenderType.CUTOUT; + case SOLID, CUTOUT, CUTOUT_MIPPED -> TerrainRenderType.CUTOUT_MIPPED; case TRANSLUCENT, TRIPWIRE -> TerrainRenderType.TRANSLUCENT; }; } diff --git a/src/main/java/net/vulkanmod/vulkan/shader/PipelineState.java b/src/main/java/net/vulkanmod/vulkan/shader/PipelineState.java index af857d070..d95553c27 100644 --- a/src/main/java/net/vulkanmod/vulkan/shader/PipelineState.java +++ b/src/main/java/net/vulkanmod/vulkan/shader/PipelineState.java @@ -379,6 +379,7 @@ private static int glToVulkan(int value) { case 516 -> VK_COMPARE_OP_GREATER; case 518 -> VK_COMPARE_OP_GREATER_OR_EQUAL; case 514 -> VK_COMPARE_OP_EQUAL; + case 513 -> VK_COMPARE_OP_LESS; default -> throw new RuntimeException("unknown blend factor.."); // case 515 -> VK_COMPARE_OP_GREATER_OR_EQUAL; diff --git a/src/main/resources/assets/vulkanmod/lang/en_us.json b/src/main/resources/assets/vulkanmod/lang/en_us.json index 28f7ba3db..cceb9b8c2 100644 --- a/src/main/resources/assets/vulkanmod/lang/en_us.json +++ b/src/main/resources/assets/vulkanmod/lang/en_us.json @@ -33,8 +33,8 @@ "vulkanmod.options.refreshRate": "Refresh Rate", - "vulkanmod.options.uniqueOpaqueLayer": "Unique opaque layer", - "vulkanmod.options.uniqueOpaqueLayer.tooltip": "Use a unique render layer for opaque terrain to improve performance.", + "vulkanmod.options.earlyZ": "Early-Z (Fast Leaves)", + "vulkanmod.options.earlyZ.tooltip": "Enables Early-Z culling: (Experimental version of Vanilla's Fast leaves)\nHas the drawback of increased drawcalls, may be slower on some hardware", "vulkanmod.options.windowedFullscreen": "Windowed Fullscreen" } \ No newline at end of file