Fix Light map flickering when multiple client levels are active

This commit is contained in:
James Seibel
2023-10-10 19:32:08 -05:00
parent 82b2bf1434
commit ff90dc04b7
9 changed files with 29 additions and 21 deletions
@@ -76,7 +76,7 @@ public class FullDataToRenderDataTransformer
{
return null;
}
else if (MC.getWrappedClientWorld() == null)
else if (MC.getWrappedClientLevel() == null)
{
// if the client is no longer loaded in the world, render sources cannot be created
return null;
@@ -26,7 +26,6 @@ import com.seibel.distanthorizons.core.dataObjects.fullData.accessor.SingleColum
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.CompleteFullDataSource;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.interfaces.IFullDataSource;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
import com.seibel.distanthorizons.core.file.structure.ClientOnlySaveStructure;
import com.seibel.distanthorizons.core.generation.DhLightingEngine;
import com.seibel.distanthorizons.core.level.DhClientLevel;
@@ -178,12 +177,12 @@ public class SubDimensionLevelMatcher implements AutoCloseable
//================================//
// attempt to get a chunk at the player's pos
IChunkWrapper newlyLoadedChunk = MC_CLIENT.getWrappedClientWorld().tryGetChunk(new DhChunkPos(this.playerData.playerBlockPos));
IChunkWrapper newlyLoadedChunk = MC_CLIENT.getWrappedClientLevel().tryGetChunk(new DhChunkPos(this.playerData.playerBlockPos));
if (newlyLoadedChunk == null)
{
return null;
}
DhLightingEngine.INSTANCE.lightChunk(newlyLoadedChunk, new ArrayList<>(), MC_CLIENT.getWrappedClientWorld().hasSkyLight() ? 15 : 0);
DhLightingEngine.INSTANCE.lightChunk(newlyLoadedChunk, new ArrayList<>(), MC_CLIENT.getWrappedClientLevel().hasSkyLight() ? 15 : 0);
// build the chunk LOD
if (!LodDataBuilder.canGenerateLodFromChunk(newlyLoadedChunk))
@@ -208,7 +207,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable
//================================//
// log the start of this attempt
LOGGER.info("Attempting to determine sub-dimension for [" + MC_CLIENT.getWrappedClientWorld().getDimensionType().getDimensionName() + "]");
LOGGER.info("Attempting to determine sub-dimension for [" + MC_CLIENT.getWrappedClientLevel().getDimensionType().getDimensionName() + "]");
LOGGER.info("Player block pos in dimension: [" + this.playerData.playerBlockPos.x + "," + this.playerData.playerBlockPos.y + "," + this.playerData.playerBlockPos.z + "]");
LOGGER.info("Potential Sub Dimension folders: [" + this.potentialLevelFolders.size() + "]");
@@ -29,7 +29,6 @@ import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
import com.seibel.distanthorizons.core.pos.DhLodPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.CompleteFullDataSource;
import com.seibel.distanthorizons.core.render.LodQuadTree;
@@ -38,7 +37,7 @@ import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
import com.seibel.distanthorizons.coreapi.util.math.Mat4f;
import org.apache.logging.log4j.Logger;
@@ -146,7 +145,7 @@ public class ClientLevelModule implements Closeable
// either the renderer hasn't been started yet, or is being reloaded
return;
}
ClientRenderState.renderer.drawLODs(mcModelViewMatrix, mcProjectionMatrix, partialTicks, profiler);
ClientRenderState.renderer.drawLODs(ClientRenderState.clientLevelWrapper, mcModelViewMatrix, mcProjectionMatrix, partialTicks, profiler);
}
public void stopRenderer()
@@ -274,9 +273,8 @@ public class ClientLevelModule implements Closeable
public static class ClientRenderState
{
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
public final ILevelWrapper levelWrapper;
public final IClientLevelWrapper clientLevelWrapper;
public final LodQuadTree quadtree;
public final RenderSourceFileHandler renderSourceFileHandler;
public final LodRenderer renderer;
@@ -285,7 +283,7 @@ public class ClientLevelModule implements Closeable
IDhClientLevel dhClientLevel, IFullDataSourceProvider fullDataSourceProvider,
AbstractSaveStructure saveStructure)
{
this.levelWrapper = dhClientLevel.getLevelWrapper();
this.clientLevelWrapper = dhClientLevel.getClientLevelWrapper();
this.renderSourceFileHandler = new RenderSourceFileHandler(fullDataSourceProvider, dhClientLevel, saveStructure);
this.quadtree = new LodQuadTree(dhClientLevel, Config.Client.Advanced.Graphics.Quality.lodChunkRenderDistance.get() * LodUtil.CHUNK_WIDTH,
@@ -41,6 +41,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.misc.ILightMapWrapper;
import com.seibel.distanthorizons.api.enums.rendering.EFogColorMode;
import com.seibel.distanthorizons.core.render.fog.LodFogConfig;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IIrisAccessor;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
import com.seibel.distanthorizons.coreapi.util.math.Mat4f;
import com.seibel.distanthorizons.coreapi.util.math.Vec3d;
import com.seibel.distanthorizons.coreapi.util.math.Vec3f;
@@ -178,7 +179,7 @@ public class LodRenderer
}
}
public void drawLODs(Mat4f baseModelViewMatrix, Mat4f baseProjectionMatrix, float partialTicks, IProfilerWrapper profiler)
public void drawLODs(IClientLevelWrapper clientLevelWrapper, Mat4f baseModelViewMatrix, Mat4f baseProjectionMatrix, float partialTicks, IProfilerWrapper profiler)
{
if (this.rendererClosed)
{
@@ -203,6 +204,14 @@ public class LodRenderer
return;
}
// Note: Since lightmapTexture is changing every frame, it's faster to recreate it than to reuse the old one.
ILightMapWrapper lightmap = MC_RENDER.getLightmapWrapper(clientLevelWrapper);
if (lightmap == null)
{
// this shouldn't normally happen, but just in case
return;
}
// Save Minecraft's GL state so it can be restored at the end of LOD rendering
LagSpikeCatcher drawSaveGLState = new LagSpikeCatcher();
GLState minecraftGlState = new GLState();
@@ -307,10 +316,8 @@ public class LodRenderer
/*---------Fill uniform data--------*/
this.shaderProgram.fillUniformData(modelViewProjectionMatrix, /*Light map = GL_TEXTURE0*/ 0,
MC.getWrappedClientWorld().getMinHeight(), vanillaBlockRenderedDistance);
MC.getWrappedClientLevel().getMinHeight(), vanillaBlockRenderedDistance);
// Note: Since lightmapTexture is changing every frame, it's faster to recreate it than to reuse the old one.
ILightMapWrapper lightmap = MC_RENDER.getLightmapWrapper();
lightmap.bind();
if (ENABLE_IBO)
{
@@ -116,7 +116,7 @@ public class FogShader extends AbstractShaderRenderer
if (this.nearFogStartUniform != -1) this.shader.setUniform(this.nearFogStartUniform, nearFogStart);
if (this.nearFogLengthUniform != -1) this.shader.setUniform(this.nearFogLengthUniform, nearFogLen);
if (this.fogScaleUniform != -1) this.shader.setUniform(this.fogScaleUniform, 1.f / lodDrawDistance);
if (this.fogVerticalScaleUniform != -1) this.shader.setUniform(this.fogVerticalScaleUniform, 1.f / MC.getWrappedClientWorld().getHeight());
if (this.fogVerticalScaleUniform != -1) this.shader.setUniform(this.fogVerticalScaleUniform, 1.f / MC.getWrappedClientLevel().getHeight());
}
private Color getFogColor(float partialTicks)
@@ -272,7 +272,7 @@ public class RenderUtil
return false;
}
if (MC_RENDER.getLightmapWrapper() == null)
if (MC_RENDER.getLightmapWrapper(levelWrapper) == null)
{
return false;
}
@@ -68,7 +68,7 @@ public class DhApiWorldProxy implements IDhApiWorldProxy
if (!MC_SHARED.isDedicatedServer())
{
return MC_CLIENT.getWrappedClientWorld();
return MC_CLIENT.getWrappedClientLevel();
}
else
{
@@ -26,6 +26,7 @@ import java.util.UUID;
import com.seibel.distanthorizons.core.enums.EDhDirection;
import com.seibel.distanthorizons.core.pos.DhBlockPos;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
@@ -82,7 +83,7 @@ public interface IMinecraftClientWrapper extends IBindable
* Returns the level the client is currently in. <br>
* Returns null if the client isn't in a level.
*/
ILevelWrapper getWrappedClientWorld();
IClientLevelWrapper getWrappedClientLevel();
/** Please move over to getInstallationDirectory() within the IMinecraftSharedWrapper */
@Deprecated
@@ -35,6 +35,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import org.jetbrains.annotations.Nullable;
/**
* Contains everything related to
@@ -108,7 +109,7 @@ public interface IMinecraftRenderWrapper extends IBindable
IWrapperFactory factory = SingletonInjector.INSTANCE.get(IWrapperFactory.class);
IVersionConstants versionConstants = SingletonInjector.INSTANCE.get(IVersionConstants.class);
IMinecraftClientWrapper minecraft = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
ILevelWrapper clientWorld = minecraft.getWrappedClientWorld();
ILevelWrapper clientWorld = minecraft.getWrappedClientLevel();
int chunkDist = this.getRenderDistance() + 1; // For some reason having '+1' is actually closer to real value
@@ -135,7 +136,9 @@ public interface IMinecraftRenderWrapper extends IBindable
return renderedPos;
}
ILightMapWrapper getLightmapWrapper();
/** Can return null if the given level hasn't had a light map assigned to it */
@Nullable
ILightMapWrapper getLightmapWrapper(ILevelWrapper level);
}