Fix terrain disappearing at screen edges with compute culling (#2212)

This commit is contained in:
Jason Mitchell authored and GitHub committed 2026-10-04 13:05:14 -07:00
1 parent 6dfb0312b1
commit fcf8ad064a
8 files changed
+168 -98

No files matched your search

@@ -84,6 +84,8 @@ public final class FlybyRunner {
private boolean vsyncOverridden;
private boolean showDebugInfoSaved;
private boolean showDebugInfoOverridden;
private int cameraSaved;
private boolean cameraOverridden;
private int shotEvery;
private int nextShot;
private int shot;
@@ -375,6 +377,11 @@ public final class FlybyRunner {
this.showDebugInfoOverridden = true;
mc.gameSettings.showDebugInfo = true;
}
if (!this.cameraOverridden) {
this.cameraSaved = mc.gameSettings.thirdPersonView;
this.cameraOverridden = true;
mc.gameSettings.thirdPersonView = SystemProperties.FLYBY_CAMERA.ordinal();
}
if ("isbrh".equals(SystemProperties.FLYBY_CRASH_TEST)) {
IsbrhTestRenderer.armCrashTest();
}
@@ -535,7 +542,7 @@ public final class FlybyRunner {
this.nextShot = this.shotEvery / 2;
FramePacer.beginStats();
final String config = "backend=" + GLStateManager.getRenderBackendName() + " pacing=" + SystemProperties.FLYBY_PACING + " vsync=" + GLStateManager.getEffectiveVSyncMode() + " discard=" + (mc.getIntegratedServer() != null);
final String config = "backend=" + GLStateManager.getRenderBackendName() + " pacing=" + SystemProperties.FLYBY_PACING + " vsync=" + GLStateManager.getEffectiveVSyncMode() + " discard=" + (mc.getIntegratedServer() != null) + " camera=" + SystemProperties.FLYBY_CAMERA;
if (Tracy.ENABLED) {
Tracy.message("flyby start route=" + this.route.id() + " length=" + this.runLength + this.route.lengthUnit() + " speed=" + this.route.speedOr(this.speed) + "b/t ticks=" + this.runTicks + " " + config);
}
@@ -757,6 +764,9 @@ public final class FlybyRunner {
final String summary = this.summarise(elapsedNs, player);
LOGGER.info(summary);
LOGGER.info(FramePacer.endStats());
if (mc.gameSettings.thirdPersonView != SystemProperties.FLYBY_CAMERA.ordinal()) {
LOGGER.warn("Flyby: camera left {} during the run (thirdPersonView={}), screenshots are not comparable", SystemProperties.FLYBY_CAMERA, mc.gameSettings.thirdPersonView);
}
if (mc.thePlayer != null) {
mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + "[Angelica] " + EnumChatFormatting.WHITE + summary));
}
@@ -787,6 +797,7 @@ public final class FlybyRunner {
this.returnToOrigin(player);
this.restorePauseOnLostFocus(mc);
this.restoreShowDebugInfo(mc);
this.restoreCamera(mc);
this.armed = false;
sceneGuarded = false;
this.sceneClearRequested = this.sceneCommands.length > 0;
@@ -819,6 +830,12 @@ public final class FlybyRunner {
this.showDebugInfoOverridden = false;
}
private void restoreCamera(Minecraft mc) {
if (!this.cameraOverridden) return;
mc.gameSettings.thirdPersonView = this.cameraSaved;
this.cameraOverridden = false;
}
private void returnToOrigin(EntityClientPlayerMP player) {
player.motionX = 0.0D;
player.motionY = 0.0D;
@@ -969,6 +986,7 @@ public final class FlybyRunner {
final Minecraft mc = Minecraft.getMinecraft();
this.restorePauseOnLostFocus(mc);
this.restoreShowDebugInfo(mc);
this.restoreCamera(mc);
this.armed = false;
this.stopRecording(mc);
this.pendingRequest.set(null);
@@ -1,5 +1,7 @@
package com.gtnewhorizons.angelica.rendering.culling;
import org.embeddedt.embeddium.impl.render.viewport.CameraTransform;
import org.joml.Matrix4f;
import org.joml.Matrix4fc;
import java.nio.ByteBuffer;
@@ -10,9 +12,11 @@ public final class FrustumExtractor {
public static final int UBO_SIZE_BYTES = 160;
public static final int PLANE_COUNT = 6;
private static final float SECTION_HALF_EXTENT = 8.0f + 1.0f + 0.125f;
private static final float SECTION_CENTER = 8.0f;
private static final int PLANE_STRIDE = 16;
private static final int CONTROL_OFFSET = 96;
private static final int CAMERA_WORLD_OFFSET = 112;
private static final int CAMERA_BLOCK_OFFSET = 112;
private static final int BATCH_OFFSET = 128;
private static final int PYR_OFFSET = 144;
@@ -22,24 +26,26 @@ public final class FrustumExtractor {
return ByteBuffer.allocateDirect(UBO_SIZE_BYTES).order(ByteOrder.nativeOrder());
}
public static void writeStd140(Matrix4fc mvp, int visibleCount, int indexPointerMask, ByteBuffer out) {
public static void writeFrustum(Matrix4fc projection, Matrix4fc modelView, CameraTransform camera, Matrix4f mvp, ByteBuffer out) {
projection.mul(modelView, mvp);
final float r0x = mvp.m00(), r0y = mvp.m10(), r0z = mvp.m20(), r0w = mvp.m30();
final float r1x = mvp.m01(), r1y = mvp.m11(), r1z = mvp.m21(), r1w = mvp.m31();
final float r2x = mvp.m02(), r2y = mvp.m12(), r2z = mvp.m22(), r2w = mvp.m32();
final float r3x = mvp.m03(), r3y = mvp.m13(), r3z = mvp.m23(), r3w = mvp.m33();
final float cx = SECTION_CENTER - camera.fracX;
final float cy = SECTION_CENTER - camera.fracY;
final float cz = SECTION_CENTER - camera.fracZ;
writePlane(out, 0 * PLANE_STRIDE, r3x + r0x, r3y + r0y, r3z + r0z, r3w + r0w);
writePlane(out, 1 * PLANE_STRIDE, r3x - r0x, r3y - r0y, r3z - r0z, r3w - r0w);
writePlane(out, 2 * PLANE_STRIDE, r3x + r1x, r3y + r1y, r3z + r1z, r3w + r1w);
writePlane(out, 3 * PLANE_STRIDE, r3x - r1x, r3y - r1y, r3z - r1z, r3w - r1w);
writePlane(out, 4 * PLANE_STRIDE, r3x + r2x, r3y + r2y, r3z + r2z, r3w + r2w);
writePlane(out, 5 * PLANE_STRIDE, r3x - r2x, r3y - r2y, r3z - r2z, r3w - r2w);
writePlane(out, 0 * PLANE_STRIDE, r3x + r0x, r3y + r0y, r3z + r0z, r3w + r0w, cx, cy, cz);
writePlane(out, 1 * PLANE_STRIDE, r3x - r0x, r3y - r0y, r3z - r0z, r3w - r0w, cx, cy, cz);
writePlane(out, 2 * PLANE_STRIDE, r3x + r1x, r3y + r1y, r3z + r1z, r3w + r1w, cx, cy, cz);
writePlane(out, 3 * PLANE_STRIDE, r3x - r1x, r3y - r1y, r3z - r1z, r3w - r1w, cx, cy, cz);
writePlane(out, 4 * PLANE_STRIDE, r3x + r2x, r3y + r2y, r3z + r2z, r3w + r2w, cx, cy, cz);
writePlane(out, 5 * PLANE_STRIDE, r3x - r2x, r3y - r2y, r3z - r2z, r3w - r2w, cx, cy, cz);
out.putInt(CONTROL_OFFSET + 0, visibleCount);
out.putInt(CONTROL_OFFSET + 4, indexPointerMask);
out.putInt(CONTROL_OFFSET + 8, 0);
out.putInt(CONTROL_OFFSET + 12, 0);
out.putInt(BATCH_OFFSET, 0);
out.putInt(CAMERA_BLOCK_OFFSET + 0, camera.intX);
out.putInt(CAMERA_BLOCK_OFFSET + 4, camera.intY);
out.putInt(CAMERA_BLOCK_OFFSET + 8, camera.intZ);
}
public static void patchBatchEntryBase(int entryBase, ByteBuffer out) {
@@ -61,17 +67,10 @@ public final class FrustumExtractor {
out.putInt(CONTROL_OFFSET + 8, bypass ? 1 : 0);
}
public static void patchCameraWorld(float x, float y, float z, ByteBuffer out) {
out.putFloat(CAMERA_WORLD_OFFSET + 0, x);
out.putFloat(CAMERA_WORLD_OFFSET + 4, y);
out.putFloat(CAMERA_WORLD_OFFSET + 8, z);
}
private static void writePlane(ByteBuffer out, int offset, float a, float b, float c, float d) {
final float invLen = 1.0f / (float) Math.sqrt(a * a + b * b + c * c);
out.putFloat(offset + 0, a * invLen);
out.putFloat(offset + 4, b * invLen);
out.putFloat(offset + 8, c * invLen);
out.putFloat(offset + 12, d * invLen);
private static void writePlane(ByteBuffer out, int offset, float a, float b, float c, float d, float cx, float cy, float cz) {
out.putFloat(offset + 0, a);
out.putFloat(offset + 4, b);
out.putFloat(offset + 8, c);
out.putFloat(offset + 12, d + SECTION_HALF_EXTENT * (Math.abs(a) + Math.abs(b) + Math.abs(c)) + a * cx + b * cy + c * cz);
}
}
@@ -28,7 +28,6 @@ import org.embeddedt.embeddium.impl.render.chunk.region.RenderRegion;
import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass;
import org.embeddedt.embeddium.impl.render.viewport.CameraTransform;
import org.joml.Matrix4f;
import org.joml.Matrix4fc;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL40;
@@ -132,7 +131,6 @@ public final class GpuTerrainCuller {
private ByteBuffer uboBytes;
private Matrix4f mvp;
private Matrix4f mvNoTranslation;
private int passOutputBase;
private ChunkPrimitiveType walkPrimitiveType;
@@ -399,17 +397,8 @@ public final class GpuTerrainCuller {
uboBytes = FrustumExtractor.allocateUboByteBuffer();
}
final boolean shadow = ShadowRenderer.ACTIVE;
final Matrix4fc proj = matrices.projection();
final Matrix4fc mv = matrices.modelView();
if (mvp == null) mvp = new Matrix4f();
if (mvNoTranslation == null) mvNoTranslation = new Matrix4f();
mvNoTranslation.set(mv).setTranslation(0f, 0f, 0f);
proj.mul(mvNoTranslation, mvp);
final float camX = (float) camera.intX + camera.fracX;
final float camY = (float) camera.intY + camera.fracY;
final float camZ = (float) camera.intZ + camera.fracZ;
FrustumExtractor.writeStd140(mvp, 0, 0, uboBytes);
FrustumExtractor.patchCameraWorld(camX, camY, camZ, uboBytes);
FrustumExtractor.writeFrustum(matrices.projection(), matrices.modelView(), camera, mvp, uboBytes);
FrustumExtractor.patchBypassFrustum(shadow, uboBytes);
frustumUboBytes = uboBytes;
@@ -459,7 +448,7 @@ public final class GpuTerrainCuller {
}
if (computeActiveThisPass) {
prepareFrustumUbo(matrices, camera);
if (!chained) prepareFrustumUbo(matrices, camera);
syncSectionMetaIfDirty();
walkPass(renderLists, AngelicaRenderPassConfiguration.TRANSLUCENT_PASS, occlusionCamera, useBlockFaceCulling);