Add automatic overdraw prevention to improve fading

This commit is contained in:
James Seibel
2025-01-11 17:59:21 -06:00
parent 9adcfd8143
commit 9a3d36757f
5 changed files with 49 additions and 8 deletions
@@ -681,13 +681,15 @@ public class Config
public static class Culling
{
public static ConfigEntry<Double> overdrawPrevention = new ConfigEntry.Builder<Double>()
.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."
@@ -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
@@ -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;
@@ -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
@@ -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":