Skip to content

Commit

Permalink
Include the perspective matrix when marking graph as dirty
Browse files Browse the repository at this point in the history
  • Loading branch information
mcrcortex authored and mcrcortex committed Jul 23, 2024
1 parent d649cac commit e82a1cb
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.joml.Matrix4f;
import org.joml.Vector3d;

import java.util.Collection;
Expand All @@ -57,6 +58,7 @@ public class SodiumWorldRenderer {
private Vector3d lastCameraPos;
private double lastCameraPitch, lastCameraYaw;
private float lastFogDistance;
private Matrix4f lastProjectionMatrix;

private boolean useEntityCulling;

Expand Down Expand Up @@ -179,20 +181,27 @@ public void setupTerrain(Camera camera,

Vec3 posRaw = camera.getPosition();
Vector3d pos = new Vector3d(posRaw.x(), posRaw.y(), posRaw.z());
Matrix4f projectionMatrix = new Matrix4f(RenderSystem.getProjectionMatrix());
float pitch = camera.getXRot();
float yaw = camera.getYRot();
float fogDistance = RenderSystem.getShaderFogEnd();

if (this.lastCameraPos == null) {
this.lastCameraPos = new Vector3d(pos);
}
if (this.lastProjectionMatrix == null) {
this.lastProjectionMatrix = new Matrix4f(projectionMatrix);
}
boolean cameraLocationChanged = !pos.equals(this.lastCameraPos);
boolean cameraAngleChanged = pitch != this.lastCameraPitch || yaw != this.lastCameraYaw || fogDistance != this.lastFogDistance;
boolean cameraProjectionChanged = !projectionMatrix.equals(this.lastProjectionMatrix);

this.lastProjectionMatrix = projectionMatrix;

this.lastCameraPitch = pitch;
this.lastCameraYaw = yaw;

if (cameraLocationChanged || cameraAngleChanged) {
if (cameraLocationChanged || cameraAngleChanged || cameraProjectionChanged) {
this.renderSectionManager.markGraphDirty();
}

Expand Down

0 comments on commit e82a1cb

Please sign in to comment.