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 index d55b5bf89..1d851dfe4 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/rendering/SeamlessOverdraw.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/rendering/SeamlessOverdraw.java @@ -16,18 +16,20 @@ 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) + public static float[] overwriteMinecraftNearFarClipPlanes(Matrix4f minecraftProjectionMatrix, float previousPartialTicks) { - FloatBuffer matrixFloatBuffer = FloatBuffer.allocate(16); + float[] matrixFloatArray; #if PRE_MC_1_19_4 + FloatBuffer matrixFloatBuffer = FloatBuffer.allocate(16); minecraftProjectionMatrix.store(matrixFloatBuffer); + matrixFloatArray = matrixFloatBuffer.array(); #else - minecraftProjectionMatrix.get(matrixFloatBuffer); + // Passing float buffers in caused native code crashes, so we are passing in a float array instead + matrixFloatArray = new float[16]; + minecraftProjectionMatrix.get(matrixFloatArray); #endif - 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. @@ -36,8 +38,7 @@ public class SeamlessOverdraw 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; + return matrixFloatArray; } } 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 337485551..c4af050fe 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientProxy.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientProxy.java @@ -207,12 +207,12 @@ public class FabricClientProxy // experimental proof-of-concept option if (Config.Client.Advanced.Graphics.AdvancedGraphics.seamlessOverdraw.get()) { - FloatBuffer modifiedMatrixBuffer = SeamlessOverdraw.overwriteMinecraftNearFarClipPlanes(renderContext.projectionMatrix(), renderContext.tickDelta()); + float[] matrixFloatArray = SeamlessOverdraw.overwriteMinecraftNearFarClipPlanes(renderContext.projectionMatrix(), renderContext.tickDelta()); #if PRE_MC_1_19_4 - renderContext.projectionMatrix().load(modifiedMatrixBuffer); + renderContext.projectionMatrix().load(FloatBuffer.wrap(matrixFloatArray)); #else - renderContext.projectionMatrix().set(modifiedMatrixBuffer); + renderContext.projectionMatrix().set(matrixFloatArray); #endif } } 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 29dc9d376..da55ba536 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 @@ -137,12 +137,12 @@ public class MixinLevelRenderer // experimental proof-of-concept option if (Config.Client.Advanced.Graphics.AdvancedGraphics.seamlessOverdraw.get()) { - FloatBuffer modifiedMatrixBuffer = SeamlessOverdraw.overwriteMinecraftNearFarClipPlanes(projectionMatrix, previousPartialTicks); + float[] matrixFloatArray = SeamlessOverdraw.overwriteMinecraftNearFarClipPlanes(projectionMatrix, previousPartialTicks); #if PRE_MC_1_19_4 - projectionMatrix.load(modifiedMatrixBuffer); + projectionMatrix.load(FloatBuffer.wrap(matrixFloatArray)); #else - projectionMatrix.set(modifiedMatrixBuffer); + projectionMatrix.set(matrixFloatArray); #endif } }