Skip to content

Commit

Permalink
Merge branch '1.19.4' into 1.18
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/grondag/canvas/shader/data/MatrixData.java
  • Loading branch information
spiralhalo committed May 28, 2023
2 parents 75ea4f5 + ea5a9b7 commit de8162a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/grondag/canvas/shader/data/MatrixData.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.vram.frex.api.math.FastMatrix4f;
import io.vram.frex.api.math.FastMatrix3f;

import grondag.canvas.CanvasMod;
import grondag.canvas.mixinterface.GameRendererExt;

public final class MatrixData {
Expand All @@ -45,6 +46,17 @@ private MatrixData() { }
IDENTITY.setIdentity();
}

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.setIdentity();
}
}

static void update(PoseStack.Pose view, Matrix4f projectionMatrix, Camera camera, float tickDelta) {
// write values for prior frame before updating
viewMatrixExt.f_writeToBuffer(VIEW_LAST * 16, MATRIX_DATA);
Expand All @@ -53,6 +65,11 @@ static void update(PoseStack.Pose view, Matrix4f projectionMatrix, Camera camera
cleanProjMatrixExt.f_writeToBuffer(CLEAN_PROJ_LAST * 16, MATRIX_DATA);
cleanViewProjMatrixExt.f_writeToBuffer(CLEAN_VP_LAST * 16, MATRIX_DATA);

if (!sanitizedOnce) {
fixVanillaBug(projectionMatrix);
sanitizedOnce = true;
}

((FastMatrix3f) (Object) viewNormalMatrix).f_set((FastMatrix3f) (Object) view.normal());

viewMatrixExt.f_set((FastMatrix4f) (Object) view.pose());
Expand Down

0 comments on commit de8162a

Please sign in to comment.