diff --git a/src/main/java/grondag/canvas/shader/data/MatrixData.java b/src/main/java/grondag/canvas/shader/data/MatrixData.java index f60a77673..a88e591de 100644 --- a/src/main/java/grondag/canvas/shader/data/MatrixData.java +++ b/src/main/java/grondag/canvas/shader/data/MatrixData.java @@ -31,11 +31,23 @@ import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; +import grondag.canvas.CanvasMod; import grondag.canvas.mixinterface.GameRendererExt; public final class MatrixData { private MatrixData() { } + private static boolean sanitizedOnce = false; + + private static void fixVanillaBug(Matrix4f matrix) { + // this only happens in the first frame, when the loading screen is still visible + // remove this once it stops spitting out the warning + if (Float.isNaN(matrix.determinant())) { + CanvasMod.LOG.warn("Switching out projection matrix with identity because it's NaN"); + matrix.identity(); + } + } + static void update(PoseStack.Pose view, Matrix4f projectionMatrix, Camera camera, float tickDelta) { // write values for prior frame before updating viewMatrix.get(VIEW_LAST * 16, MATRIX_DATA); @@ -44,6 +56,11 @@ static void update(PoseStack.Pose view, Matrix4f projectionMatrix, Camera camera cleanProjMatrix.get(CLEAN_PROJ_LAST * 16, MATRIX_DATA); cleanViewProjMatrix.get(CLEAN_VP_LAST * 16, MATRIX_DATA); + if (!sanitizedOnce) { + fixVanillaBug(projectionMatrix); + sanitizedOnce = true; + } + viewNormalMatrix.set(view.normal()); viewMatrix.set(view.pose());