diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/DhApiRenderProxy.java b/core/src/main/java/com/seibel/distanthorizons/core/render/DhApiRenderProxy.java index a330c3e95..17aa0dddc 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/DhApiRenderProxy.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/DhApiRenderProxy.java @@ -103,6 +103,6 @@ public class DhApiRenderProxy implements IDhApiRenderProxy public boolean getDeferTransparentRendering() { return this.deferTransparentRendering; } @Override - public float getNearClipPlaneDistanceInBlocks(float partialTicks) { return RenderUtil.getNearClipPlaneDistanceInBlocks(partialTicks); } + public float getNearClipPlaneDistanceInBlocks(float partialTicks) { return RenderUtil.getNearClipPlaneInBlocks(); } } 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 4a753df04..892f236e0 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 @@ -204,18 +204,12 @@ public class DhTerrainShaderProgram extends ShaderProgram implements IDhApiShade this.setUniform(this.uIsWhiteWorld, Config.Client.Advanced.Debugging.enableWhiteWorld.get()); // Clip Uniform - float dhNearClipDistance = RenderUtil.getNearClipPlaneInBlocksForFading(renderParameters.partialTicks); + float dhNearClipDistance = RenderUtil.getNearClipPlaneInBlocks(); if (!Config.Client.Advanced.Debugging.lodOnlyMode.get()) { // this added value prevents the near clip plane and discard circle from touching, which looks bad dhNearClipDistance += 16f; } - // if the player is very high up and the near clip plane has been modified, disable the distance clipping - // we're high enough that nothing will render on top of the player and this can cause issues otherwise - if (RenderUtil.getHeightBasedNearClipOverride() != -1) - { - dhNearClipDistance = 1.0f; - } this.setUniform(this.uClipDistance, dhNearClipDistance); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/RenderParams.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/RenderParams.java index 183fe6aff..c40f6a5e5 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/RenderParams.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/RenderParams.java @@ -54,7 +54,7 @@ public class RenderParams extends DhApiRenderParam { super(renderPass, newPartialTicks, - RenderUtil.getNearClipPlaneDistanceInBlocks(newPartialTicks), RenderUtil.getFarClipPlaneDistanceInBlocks(), + RenderUtil.getNearClipPlaneInBlocks(), RenderUtil.getFarClipPlaneDistanceInBlocks(), newMcProjectionMatrix, newMcModelViewMatrix, RenderUtil.createLodProjectionMatrix(newMcProjectionMatrix, newPartialTicks), RenderUtil.createLodModelViewMatrix(newMcModelViewMatrix), clientLevelWrapper.getMinHeight(), diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/BeaconRenderHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/BeaconRenderHandler.java index 4f2b4fbef..e5935fa2b 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/BeaconRenderHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/generic/BeaconRenderHandler.java @@ -275,10 +275,10 @@ public class BeaconRenderHandler this.updateLock.lock(); Vec3d cameraPos = MC_RENDER.getCameraExactPosition(); - double mcRenderDistance = MC_RENDER.getRenderDistance() * LodUtil.CHUNK_WIDTH; - // multiplying by overdraw prevention helps reduce beacons from rendering strangely + + // fading by the overdraw prevention amount helps reduce beacons from rendering strangely // on the border of DH's render distance - mcRenderDistance *= RenderUtil.getAutoOverdrawPrevention(); + float dhFadeDistance = RenderUtil.getNearClipPlaneInBlocks(); // Clear the existing box group so we can re-populate it. @@ -293,7 +293,7 @@ public class BeaconRenderHandler { // if a beacon is outside the vanilla render distance render it double distance = Vec3d.getHorizontalDistance(cameraPos, box.minPos); - if (distance > mcRenderDistance) + if (distance > dhFadeDistance) { this.beaconBoxGroup.add(box); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOApplyShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOApplyShader.java index 1a1adf0f6..7f81e21c1 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOApplyShader.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOApplyShader.java @@ -106,7 +106,7 @@ public class SSAOApplyShader extends AbstractShaderRenderer if (this.gNearUniform >= 0) { GL32.glUniform1f(this.gNearUniform, - RenderUtil.getNearClipPlaneDistanceInBlocks(partialTicks)); + RenderUtil.getNearClipPlaneInBlocks()); } if (this.gFarUniform >= 0) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/VanillaFadeShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/VanillaFadeShader.java index 605e18cb5..e7129d12e 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/VanillaFadeShader.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/VanillaFadeShader.java @@ -112,7 +112,7 @@ public class VanillaFadeShader extends AbstractShaderRenderer this.shader.setUniform(this.uDhInvMvmProj, this.inverseDhMvmProjMatrix); - float dhNearClipDistance = RenderUtil.getNearClipPlaneInBlocksForFading(partialTicks); + float dhNearClipDistance = RenderUtil.getNearClipPlaneInBlocks(); // 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 84c536a5a..dc6bbeb93 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 @@ -57,6 +57,7 @@ public class RenderUtil //=====================// // matrix manipulation // //=====================// + //region /** * create and return a new projection matrix based on MC's modelView and projection matrices @@ -69,7 +70,7 @@ public class RenderUtil // culling to take effect instead of seeing the near clip plane. float nearClipDist = RenderUtil.getNearClipPlaneDistanceInBlocks(partialTicks); // limit the near clip plane if we are close to the ground - if (getHeightBasedNearClipOverride() == -1) + if (getHeightBasedNearClipOverrideBlockDistance() == -1) { // min() used to prevent the near clip plane from becoming visible at large vanilla render distances // DH's dithering/discard shader handles everything farther away anyway so the near clip plane @@ -94,21 +95,16 @@ public class RenderUtil return mcModelViewMat.copy(); } + //endregion - //=============// - // clip planes // - //=============// - 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); - } - /** TODO this should be moved into the config file or something, this is confusing and obtuse to use */ - @Deprecated - public static float getAutoOverdrawPrevention() + //=================// + // near clip plane // + //=================// + //region + + public static float getNearClipPlaneInBlocks() { float overdraw = Config.Client.Advanced.Graphics.Culling.overdrawPrevention.get().floatValue(); if (overdraw < 0) @@ -145,12 +141,7 @@ public class RenderUtil // since that will cause rendering issues overdraw = MathUtil.clamp(0.05f, overdraw, 1.0f); } - - return overdraw; - } - public static float getNearClipPlaneInBlocksForFading(float partialTicks) - { - float overdraw = getAutoOverdrawPrevention(); + if (Config.Client.Advanced.Graphics.Culling.reduceOverdrawWithFastMovement.get()) { @@ -171,9 +162,9 @@ public class RenderUtil } } - return getNearClipPlaneDistanceInBlocks(partialTicks, overdraw); + return getNearClipPlaneDistanceInBlocks(overdraw); } - private static float getNearClipPlaneDistanceInBlocks(float partialTicks, float overdrawPreventionPercent) + private static float getNearClipPlaneDistanceInBlocks(float overdrawPreventionPercent) { int chunkRenderDistance = MC_RENDER.getRenderDistance(); int vanillaBlockRenderedDistance = chunkRenderDistance * LodUtil.CHUNK_WIDTH; @@ -185,10 +176,6 @@ public class RenderUtil } else { - // TODO make this option dependent on player speed. - // 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 = vanillaBlockRenderedDistance; nearClipPlane *= overdrawPreventionPercent; @@ -202,7 +189,7 @@ public class RenderUtil // TODO move into method and use to override discard value in shader program - float heightOverride = getHeightBasedNearClipOverride(); + float heightOverride = getHeightBasedNearClipOverrideBlockDistance(); if (heightOverride != -1.0f) { nearClipPlane = heightOverride; @@ -222,19 +209,15 @@ public class RenderUtil / Math.sqrt(1d + MathUtil.pow2(Math.tan(fov / 180d * Math.PI / 2d)) * (MathUtil.pow2(aspectRatio) + 1d))); } - public static int getFarClipPlaneDistanceInBlocks() - { - int lodChunkDist = Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius.get(); - int lodBlockDist = lodChunkDist * LodUtil.CHUNK_WIDTH; - // * 2 to prevent clipping when high above the world - return (lodBlockDist + LodUtil.REGION_WIDTH) * 2; - } - /** @return -1 if no override is necessary */ - public static float getHeightBasedNearClipOverride() + /** + * Returns a new distance if the player is sufficiently far above the world. + * @return -1 if no override is necessary + */ + public static float getHeightBasedNearClipOverrideBlockDistance() { - // TODO always using the client level like this might cause issues with immersive portals and the like, - // but for now it should work well enough + // always using the client level like this might cause issues with immersive portals and the like, + // but for now it works well enough IClientLevelWrapper level = MC.getWrappedClientLevel(); // a level should always be loaded, but just in case if (level != null) @@ -252,6 +235,26 @@ public class RenderUtil return -1.0f; } + //endregion + + + + //================// + // far clip plane // + //================// + + //region + + public static int getFarClipPlaneDistanceInBlocks() + { + int lodChunkDist = Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistanceRadius.get(); + int lodBlockDist = lodChunkDist * LodUtil.CHUNK_WIDTH; + // * 2 to prevent clipping when high above the world + return (lodBlockDist + LodUtil.REGION_WIDTH) * 2; + } + + //endregion + }