Fix camera position off-by-one with immersive portals

This commit is contained in:
James Seibel
2026-06-02 17:40:58 -05:00
parent 2afefd03b4
commit 9e092091d2
4 changed files with 18 additions and 8 deletions
@@ -450,8 +450,6 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
this.boxIndexBuffer.bind(); this.boxIndexBuffer.bind();
DhVec3d camPos = MC_RENDER.getCameraExactPosition();
// rendering // // rendering //
@@ -512,11 +510,11 @@ public class GlGenericObjectRenderer implements IDhGenericRenderer
{ {
if (this.instancedRenderingAvailable) if (this.instancedRenderingAvailable)
{ {
this.renderBoxGroupInstanced(shaderProgram, renderEventParam, boxGroup, camPos, profiler); this.renderBoxGroupInstanced(shaderProgram, renderEventParam, boxGroup, renderEventParam.exactCameraPosition, profiler);
} }
else else
{ {
this.renderBoxGroupDirect(shaderProgram, renderEventParam, boxGroup, camPos, profiler); this.renderBoxGroupDirect(shaderProgram, renderEventParam, boxGroup, renderEventParam.exactCameraPosition, profiler);
} }
} }
@@ -208,7 +208,7 @@ public class GlDhFogShader extends GlAbstractShaderRenderer
this.shader.setUniform(this.uHeightFogAppliesDown, heightFogDirection.fogAppliesDown); this.shader.setUniform(this.uHeightFogAppliesDown, heightFogDirection.fogAppliesDown);
this.shader.setUniform(this.uUseSphericalFog, useSphericalFog); this.shader.setUniform(this.uUseSphericalFog, useSphericalFog);
this.shader.setUniform(this.uHeightFogMixingMode, heightFogMixingMode.value); this.shader.setUniform(this.uHeightFogMixingMode, heightFogMixingMode.value);
this.shader.setUniform(this.uCameraBlockYPos, (float)MC_RENDER.getCameraExactPosition().y); this.shader.setUniform(this.uCameraBlockYPos, (float)renderParams.exactCameraPosition.y);
} }
@@ -22,6 +22,7 @@ package com.seibel.distanthorizons.common.wrappers.minecraft;
import java.awt.Color; import java.awt.Color;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import com.seibel.distanthorizons.core.render.RenderThreadTaskHandler;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
#if MC_VER > MC_1_12_2 #if MC_VER > MC_1_12_2
@@ -216,10 +217,21 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
@Override @Override
public DhVec3d getCameraExactPosition() public DhVec3d getCameraExactPosition()
{ {
if (DelayedAccessors.IMMERSIVE_PORTALS != null) // When immersive portals is enabled getting the camera position
// outside the render thread means you may get the camera for any one of the dimensions
// immersive portals is currently rendering, which isn't what DH wants.
// We want the camera that the player is currently looking through.
if (DelayedAccessors.IMMERSIVE_PORTALS != null
&& !RenderThreadTaskHandler.INSTANCE.isCurrentThread())
{ {
// this camera position will likely be delayed by 1 frame, so it shouldn't
// be used for rendering,
// but anything else that doesn't require that level of percision is fine.
DhVec3d cameraPos = DelayedAccessors.IMMERSIVE_PORTALS.getActualCameraPos(); DhVec3d cameraPos = DelayedAccessors.IMMERSIVE_PORTALS.getActualCameraPos();
if (cameraPos != null) return cameraPos; if (cameraPos != null)
{
return cameraPos;
}
} }
#if MC_VER <= MC_1_12_2 #if MC_VER <= MC_1_12_2