diff --git a/common/src/main/java/com/seibel/distanthorizons/common/rendering/SeamlessOverdraw.java b/common/src/main/java/com/seibel/distanthorizons/common/rendering/SeamlessOverdraw.java new file mode 100644 index 000000000..4a0ab5aa3 --- /dev/null +++ b/common/src/main/java/com/seibel/distanthorizons/common/rendering/SeamlessOverdraw.java @@ -0,0 +1,33 @@ +package com.seibel.distanthorizons.common.rendering; + +import com.mojang.math.Matrix4f; +import com.seibel.distanthorizons.core.config.Config; +import com.seibel.distanthorizons.core.util.RenderUtil; + +import java.nio.FloatBuffer; + +public class SeamlessOverdraw +{ + /** + * Proof-of-concept experimental option, not intended for normal use.
+ * (Poorly) replaces Minecraft's far clip plane so it lines up with DH's near clip plane. + */ + public static FloatBuffer overwriteMinecraftNearFarClipPlanes(Matrix4f minecraftProjectionMatrix, float previousPartialTicks) + { + FloatBuffer matrixFloatBuffer = FloatBuffer.allocate(16); + minecraftProjectionMatrix.store(matrixFloatBuffer); + float[] matrixFloatArray = matrixFloatBuffer.array(); + + float dhFarClipPlane = RenderUtil.getNearClipPlaneDistanceInBlocks(previousPartialTicks); + float farClip = dhFarClipPlane * 5.1f; // magic number found via trial and error, James has no idea what it represents, except that it makes the seam between DH and vanilla rendering pretty close + float nearClip = 0.5f; // this causes issues with some vanilla rendering, specifically the wireframe around selected blocks is slightly off. Unfortunately the ratio between the near and far clip plane can't be easily modified without completely screwing up the rendering. + + // these may be the wrong index locations in any version of MC other than 1.18.2 + matrixFloatArray[10] = -((farClip + nearClip) / (farClip - nearClip)); // near clip plane + matrixFloatArray[11] = -((2 * farClip * nearClip) / (farClip - nearClip)); // far clip plane + + matrixFloatBuffer = FloatBuffer.wrap(matrixFloatArray); + return matrixFloatBuffer; + } + +} diff --git a/coreSubProjects b/coreSubProjects index f07973a1c..5a014f163 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit f07973a1ce2aef2ed39988cdebf9a2bdf4e2a6f0 +Subproject commit 5a014f163d84506825e074961ecbf97809c78b16 diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientProxy.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientProxy.java index b987a5b20..59d08d97b 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientProxy.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientProxy.java @@ -19,15 +19,19 @@ package com.seibel.distanthorizons.fabric; +import com.mojang.math.Matrix4f; +import com.seibel.distanthorizons.common.rendering.SeamlessOverdraw; import com.seibel.distanthorizons.common.wrappers.McObjectConverter; import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper; import com.seibel.distanthorizons.core.api.internal.ClientApi; import com.mojang.blaze3d.platform.InputConstants; import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper; +import com.seibel.distanthorizons.core.config.Config; import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector; import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; +import com.seibel.distanthorizons.core.util.RenderUtil; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IImmersivePortalsAccessor; import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.ISodiumAccessor; @@ -44,6 +48,7 @@ import net.fabricmc.fabric.api.event.player.UseBlockCallback; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.TitleScreen; +import java.nio.FloatBuffer; import java.util.HashSet; import net.minecraft.client.multiplayer.ClientLevel; @@ -189,10 +194,18 @@ public class FabricClientProxy } else { - clientApi.renderLods(ClientLevelWrapper.getWrapper(renderContext.world()), + this.clientApi.renderLods(ClientLevelWrapper.getWrapper(renderContext.world()), McObjectConverter.Convert(renderContext.matrixStack().last().pose()), McObjectConverter.Convert(renderContext.projectionMatrix()), renderContext.tickDelta()); + + + // experimental proof-of-concept option + if (Config.Client.Advanced.Graphics.AdvancedGraphics.seamlessOverdraw.get()) + { + FloatBuffer modifiedMatrixBuffer = SeamlessOverdraw.overwriteMinecraftNearFarClipPlanes(renderContext.projectionMatrix(), renderContext.tickDelta()); + renderContext.projectionMatrix().load(modifiedMatrixBuffer); + } } if (immersiveAccessor != null) diff --git a/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/client/MixinLevelRenderer.java b/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/client/MixinLevelRenderer.java index 35e869255..f38a64967 100644 --- a/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/client/MixinLevelRenderer.java +++ b/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/client/MixinLevelRenderer.java @@ -25,10 +25,12 @@ import com.mojang.math.Matrix4f; #else import org.joml.Matrix4f; #endif +import com.seibel.distanthorizons.common.rendering.SeamlessOverdraw; import com.seibel.distanthorizons.common.wrappers.McObjectConverter; import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper; import com.seibel.distanthorizons.core.config.Config; import com.seibel.distanthorizons.core.api.internal.ClientApi; +import com.seibel.distanthorizons.core.util.RenderUtil; import com.seibel.distanthorizons.coreapi.util.math.Mat4f; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.LevelRenderer; @@ -40,6 +42,8 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.nio.FloatBuffer; + /** * This class is used to mix in my rendering code * before Minecraft starts rendering blocks. @@ -130,6 +134,13 @@ public class MixinLevelRenderer Mat4f mcProjectionMatrix = McObjectConverter.Convert(projectionMatrix); ClientApi.INSTANCE.renderLods(ClientLevelWrapper.getWrapper(level), mcModelViewMatrix, mcProjectionMatrix, previousPartialTicks); + + // experimental proof-of-concept option + if (Config.Client.Advanced.Graphics.AdvancedGraphics.seamlessOverdraw.get()) + { + FloatBuffer modifiedMatrixBuffer = SeamlessOverdraw.overwriteMinecraftNearFarClipPlanes(projectionMatrix, previousPartialTicks); + projectionMatrix.load(modifiedMatrixBuffer); + } } if (Config.Client.Advanced.Debugging.lodOnlyMode.get())