From 9a3d36757f104951706482fc702606e8e6f46f02 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 11 Jan 2025 17:59:21 -0600 Subject: [PATCH] Add automatic overdraw prevention to improve fading --- .../distanthorizons/core/config/Config.java | 6 ++- .../renderer/DhTerrainShaderProgram.java | 2 +- .../render/renderer/shaders/FadeShader.java | 2 +- .../distanthorizons/core/util/RenderUtil.java | 45 +++++++++++++++++-- .../assets/distanthorizons/lang/en_us.json | 2 +- 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java index 2c3de88e5..35083f04c 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java @@ -681,13 +681,15 @@ public class Config public static class Culling { public static ConfigEntry overdrawPrevention = new ConfigEntry.Builder() - .setMinDefaultMax(0.0, 0.4, 1.0) + .setMinDefaultMax(0.0, 0.0, 1.0) .comment("" + "Determines how far from the camera Distant Horizons will start rendering. \n" + "Measured as a percentage of the vanilla render distance.\n" + "\n" + + "0 = auto, overdraw will change based on the vanilla render distance.\n" + + "\n" + "Higher values will prevent LODs from rendering behind vanilla blocks at a higher distance,\n" - + "but may cause holes to appear in the LODs. \n" + + "but may cause holes in the world. \n" + "Holes are most likely to appear when flying through unloaded terrain. \n" + "\n" + "Increasing the vanilla render distance increases the effectiveness of this setting." diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/DhTerrainShaderProgram.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/DhTerrainShaderProgram.java index 8b198cdc7..98e97ebd4 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/DhTerrainShaderProgram.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/DhTerrainShaderProgram.java @@ -195,7 +195,7 @@ public class DhTerrainShaderProgram extends ShaderProgram implements IDhApiShade this.setUniform(this.uWhiteWorld, Config.Client.Advanced.Debugging.enableWhiteWorld.get()); // Clip Uniform - float dhNearClipDistance = RenderUtil.getNearClipPlaneDistanceInBlocks(renderParameters.partialTicks); + float dhNearClipDistance = RenderUtil.getNearClipPlaneInBlocksForFading(renderParameters.partialTicks); if (!Config.Client.Advanced.Debugging.lodOnlyMode.get()) { // this added value prevents the near clip plane and discard circle from touching, which looks bad diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FadeShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FadeShader.java index f4c9358aa..60e73df2b 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FadeShader.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FadeShader.java @@ -112,7 +112,7 @@ public class FadeShader extends AbstractShaderRenderer if (this.inverseDhMvmProjMatrix != null) this.shader.setUniform(this.uDhInvMvmProj, this.inverseDhMvmProjMatrix); - float dhNearClipDistance = RenderUtil.getNearClipPlaneDistanceInBlocks(partialTicks); + float dhNearClipDistance = RenderUtil.getNearClipPlaneInBlocksForFading(partialTicks); // this added value prevents the near clip plane and discard circle from touching, which looks bad dhNearClipDistance += 16f; diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/RenderUtil.java b/core/src/main/java/com/seibel/distanthorizons/core/util/RenderUtil.java index 2fdbe6d1b..c3b04e41f 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/RenderUtil.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/RenderUtil.java @@ -86,7 +86,46 @@ public class RenderUtil return mcModelViewMat.copy(); } - public static float getNearClipPlaneDistanceInBlocks(float partialTicks) + public static float getNearClipPlaneDistanceInBlocks(float partialTicks) + { + // 0.2 should provide a decent distance so the clip plane isn't visible + // but far enough the fading will rarely overlap (IE only at extreme FOV) + return getNearClipPlaneDistanceInBlocks(partialTicks, 0.2f); + } + public static float getNearClipPlaneInBlocksForFading(float partialTicks) + { + float overdraw = Config.Client.Advanced.Graphics.Culling.overdrawPrevention.get().floatValue(); + + // 0 or less + if (overdraw <= 0) + { + // at low render distances this hides the vanilla RD border + int chunkRenderDistance = MC_RENDER.getRenderDistance(); + if (chunkRenderDistance <= 2) + { + overdraw = 0.2f; + } + else if (chunkRenderDistance <= 4) + { + overdraw = 0.3f; + } + else if (chunkRenderDistance <= 6) + { + overdraw = 0.6f; + } + else if (chunkRenderDistance <= 10) + { + overdraw = 0.8f; + } + else + { + overdraw = 0.9f; + } + } + + return getNearClipPlaneDistanceInBlocks(partialTicks, overdraw); + } + private static float getNearClipPlaneDistanceInBlocks(float partialTicks, float overdrawPreventionPercent) { int chunkRenderDistance = MC_RENDER.getRenderDistance(); int vanillaBlockRenderedDistance = chunkRenderDistance * LodUtil.CHUNK_WIDTH; @@ -102,8 +141,8 @@ public class RenderUtil // If the player is flying quickly, lower the near clip plane to account for slow chunk loading. // If the player is moving quickly they are less likely to notice overdraw. - nearClipPlane = Config.Client.Advanced.Graphics.Culling.overdrawPrevention.get().floatValue(); - nearClipPlane *= vanillaBlockRenderedDistance; + nearClipPlane = vanillaBlockRenderedDistance; + nearClipPlane *= overdrawPreventionPercent; // the near clip plane should never be closer than 1/10th of a block, // otherwise Z-fighting and other issues may occur diff --git a/core/src/main/resources/assets/distanthorizons/lang/en_us.json b/core/src/main/resources/assets/distanthorizons/lang/en_us.json index c1580d8b2..e96bfa89b 100644 --- a/core/src/main/resources/assets/distanthorizons/lang/en_us.json +++ b/core/src/main/resources/assets/distanthorizons/lang/en_us.json @@ -338,7 +338,7 @@ "distanthorizons.config.client.advanced.graphics.culling.overdrawPrevention": "Overdraw Prevention", "distanthorizons.config.client.advanced.graphics.culling.overdrawPrevention.@tooltip": - "Determines how far from the camera Distant Horizons will start rendering. \nMeasured as a percentage of the vanilla render distance.\n\nHigher values will prevent LODs from rendering behind vanilla blocks at a higher distance,\nbut may cause holes to appear in the LODs. \nHoles are most likely to appear when flying through unloaded terrain. \n\nIncreasing the vanilla render distance increases the effectiveness of this setting.", + "Determines how far from the camera Distant Horizons will start rendering. \nMeasured as a percentage of the vanilla render distance.\n0 = Auto, overdraw will change based on the vanilla render distance.\n\nHigher values will prevent LODs from rendering behind vanilla blocks at a higher distance,\nbut may cause holes to appear in the LODs. \nHoles are most likely to appear when flying through unloaded terrain. \n\nIncreasing the vanilla render distance increases the effectiveness of this setting.", "distanthorizons.config.client.advanced.graphics.culling.enableCaveCulling": "Cave Culling", "distanthorizons.config.client.advanced.graphics.culling.enableCaveCulling.@tooltip":