Fix lightmap, again.
This commit is contained in:
-34
@@ -163,40 +163,6 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper
|
||||
return LodUtil.getDimensionIDFromWorld(WorldWrapper.getWorldWrapper(mc.level));
|
||||
}
|
||||
|
||||
/** This texture changes every frame */
|
||||
@Override
|
||||
public ILightMapWrapper getCurrentLightMap()
|
||||
{
|
||||
// get the current lightMap if the cache is empty
|
||||
if (lightMap == null)
|
||||
{
|
||||
LightTexture tex = mc.gameRenderer.lightTexture();
|
||||
lightMap = tex.lightPixels;
|
||||
}
|
||||
return new LightMapWrapper(lightMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color int at the given pixel coordinates
|
||||
* from the current lightmap.
|
||||
* @param blockLight x location in texture space
|
||||
* @param skyLight z location in texture space
|
||||
*/
|
||||
@Override
|
||||
public int getColorIntFromLightMap(int blockLight, int skyLight)
|
||||
{
|
||||
if (lightMap == null)
|
||||
{
|
||||
//sendChatMessage("new");
|
||||
// make sure the lightMap is up-to-date
|
||||
getCurrentLightMap();
|
||||
}
|
||||
|
||||
return lightMap.getPixelRGBA(blockLight, skyLight);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=============//
|
||||
// Simple gets //
|
||||
//=============//
|
||||
|
||||
+16
-109
@@ -86,7 +86,9 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
private static final Minecraft MC = Minecraft.getInstance();
|
||||
private static final GameRenderer GAME_RENDERER = MC.gameRenderer;
|
||||
private static final IWrapperFactory FACTORY = WrapperFactory.INSTANCE;
|
||||
|
||||
|
||||
public LightMapWrapper lightmap = null;
|
||||
|
||||
@Override
|
||||
public Vec3f getLookAtVector()
|
||||
{
|
||||
@@ -216,16 +218,13 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
|
||||
public boolean usingBackupGetVanillaRenderedChunks = false;
|
||||
@Override
|
||||
public HashSet<AbstractChunkPosWrapper> getVanillaRenderedChunks()
|
||||
{
|
||||
public HashSet<AbstractChunkPosWrapper> getVanillaRenderedChunks() {
|
||||
ISodiumAccessor sodium = ModAccessorHandler.get(ISodiumAccessor.class);
|
||||
if (sodium != null)
|
||||
{
|
||||
if (sodium != null) {
|
||||
return sodium.getNormalRenderedChunks();
|
||||
}
|
||||
IOptifineAccessor optifine = ModAccessorHandler.get(IOptifineAccessor.class);
|
||||
if (optifine != null)
|
||||
{
|
||||
if (optifine != null) {
|
||||
HashSet<AbstractChunkPosWrapper> pos = optifine.getNormalRenderedChunks();
|
||||
if (pos == null)
|
||||
pos = getMaximumRenderedChunks();
|
||||
@@ -260,117 +259,18 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
+ " Using Backup Method.");
|
||||
MinecraftClientWrapper.INSTANCE.sendChatMessage(
|
||||
"\u00A7eOverdraw prevention will be worse than normal.");
|
||||
} catch (Exception e2) {}
|
||||
} catch (Exception e2) {
|
||||
}
|
||||
ApiShared.LOGGER.error("getVanillaRenderedChunks Error: ", e);
|
||||
usingBackupGetVanillaRenderedChunks = true;
|
||||
}
|
||||
}
|
||||
return getMaximumRenderedChunks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getLightmapPixels()
|
||||
{
|
||||
LightTexture tex = GAME_RENDERER.lightTexture();
|
||||
//tex.tick(); // This call makes no sense, but it fixes pause menu flicker bug
|
||||
NativeImage lightMapPixels = tex.lightTexture.getPixels();
|
||||
LightMapWrapper lightMap = new LightMapWrapper(lightMapPixels);
|
||||
|
||||
|
||||
int lightMapHeight = getLightmapTextureHeight();
|
||||
int lightMapWidth = getLightmapTextureWidth();
|
||||
|
||||
int[] pixels = new int[lightMapWidth * lightMapHeight];
|
||||
for (int u = 0; u < lightMapWidth; u++)
|
||||
{
|
||||
for (int v = 0; v < lightMapWidth; v++)
|
||||
{
|
||||
// this could probably be kept as a int, but
|
||||
// it is easier to test and see the colors when debugging this way.
|
||||
// When creating a new release this should be changed to the int version.
|
||||
int col = lightMap.getLightValue(u, v);
|
||||
|
||||
// these should both create a totally white image
|
||||
// int col =
|
||||
// Integer.MAX_VALUE;
|
||||
// int col =
|
||||
// 0b11111111 + // red
|
||||
// (0b11111111 << 8) + // green
|
||||
// (0b11111111 << 16) + // blue
|
||||
// (0b11111111 << 24); // blue
|
||||
|
||||
// int col =
|
||||
// ((c.getRed() & 0xFF) << 16) | // blue
|
||||
// ((c.getGreen() & 0xFF) << 8) | // green
|
||||
// ((c.getBlue() & 0xFF)) | // red
|
||||
// ((c.getAlpha() & 0xFF) << 24); // alpha
|
||||
|
||||
// 2D array stored in a 1D array.
|
||||
// Thank you Tim from College ;)
|
||||
pixels[u * lightMapWidth + v] = col;
|
||||
}
|
||||
}
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILightMapWrapper getLightmapWrapper() {
|
||||
return new LightMapWrapper(GAME_RENDERER.lightTexture());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int getLightmapTextureHeight()
|
||||
{
|
||||
int height = -1;
|
||||
|
||||
LightTexture lightTexture = GAME_RENDERER.lightTexture();
|
||||
if (lightTexture != null)
|
||||
{
|
||||
NativeImage tex = lightTexture.lightPixels;
|
||||
if (tex != null)
|
||||
{
|
||||
height = tex.getHeight();
|
||||
}
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightmapTextureWidth()
|
||||
{
|
||||
int width = -1;
|
||||
|
||||
LightTexture lightTexture = GAME_RENDERER.lightTexture();
|
||||
if (lightTexture != null)
|
||||
{
|
||||
NativeImage tex = lightTexture.lightPixels;
|
||||
if (tex != null)
|
||||
{
|
||||
width = tex.getWidth();
|
||||
}
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLightmapGLFormat() {
|
||||
int glFormat = -1;
|
||||
|
||||
LightTexture lightTexture = GAME_RENDERER.lightTexture();
|
||||
if (lightTexture != null) {
|
||||
NativeImage tex = lightTexture.lightPixels;
|
||||
if (tex != null) {
|
||||
glFormat = tex.format().glFormat();
|
||||
}
|
||||
}
|
||||
|
||||
return glFormat;
|
||||
return lightmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -394,4 +294,11 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
public boolean tryDisableVanillaFog() {
|
||||
return true; // Handled via MixinFogRenderer in both forge and fabric
|
||||
}
|
||||
|
||||
public void updateLightmap(NativeImage lightPixels) {
|
||||
if (lightmap== null) {
|
||||
lightmap = new LightMapWrapper();
|
||||
}
|
||||
lightmap.uploadLightmap(lightPixels);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,41 +22,46 @@ package com.seibel.lod.common.wrappers.misc;
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.seibel.lod.core.wrapperInterfaces.misc.ILightMapWrapper;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* @author James Seibel
|
||||
* @version 11-21-2021
|
||||
*/
|
||||
public class LightMapWrapper implements ILightMapWrapper
|
||||
{
|
||||
static NativeImage lightMap = null;
|
||||
private int textureId = 0;
|
||||
|
||||
private LightTexture tex;
|
||||
|
||||
public LightMapWrapper(NativeImage newLightMap)
|
||||
public LightMapWrapper()
|
||||
{
|
||||
lightMap = newLightMap;
|
||||
}
|
||||
|
||||
public LightMapWrapper(LightTexture lightTexture) {
|
||||
tex = lightTexture;
|
||||
private void createLightmap(NativeImage image)
|
||||
{
|
||||
textureId = GL32.glGenTextures();
|
||||
GL32.glBindTexture(GL32.GL_TEXTURE_2D, textureId);
|
||||
GL32.glTexImage2D(GL32.GL_TEXTURE_2D, 0, image.format().glFormat(), image.getWidth(), image.getHeight(),
|
||||
0, image.format().glFormat(), GL32.GL_UNSIGNED_BYTE, (ByteBuffer) null);
|
||||
}
|
||||
|
||||
public static void setLightMap(NativeImage newLightMap)
|
||||
public void uploadLightmap(NativeImage image)
|
||||
{
|
||||
lightMap = newLightMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightValue(int skyLight, int blockLight)
|
||||
{
|
||||
return lightMap.getPixelRGBA(skyLight, blockLight);
|
||||
int currentBind = GL32.glGetInteger(GL32.GL_TEXTURE_BINDING_2D);
|
||||
GL32.glBindTexture(GL32.GL_TEXTURE_2D, textureId);
|
||||
if (textureId == 0) {
|
||||
createLightmap(image);
|
||||
}
|
||||
// NativeImage::upload(int levelOfDetail, int xOffset, int yOffset, bool shouldCleanup?)
|
||||
image.upload(0, 0, 0, false);
|
||||
GL32.glBindTexture(GL32.GL_TEXTURE_2D, currentBind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind() {
|
||||
GL32.glBindTexture(GL32.GL_TEXTURE_2D, tex.lightTexture.getId());
|
||||
GL32.glBindTexture(GL32.GL_TEXTURE_2D, textureId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
Submodule core updated: 7eb0d62f75...25d2b9df7b
@@ -0,0 +1,28 @@
|
||||
package com.seibel.lod.fabric.mixins.events;
|
||||
|
||||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.seibel.lod.common.wrappers.minecraft.MinecraftRenderWrapper;
|
||||
import com.seibel.lod.core.api.ApiShared;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(LightTexture.class)
|
||||
public class MixinLightmap {
|
||||
@Shadow
|
||||
@Final
|
||||
public NativeImage lightPixels;
|
||||
|
||||
@Inject(method="updateLightTexture", at=@At(
|
||||
value="INVOKE",
|
||||
target="Lnet/minecraft/client/renderer/texture/DynamicTexture;upload()V"))
|
||||
public void updateLightTexture(float f, CallbackInfo ci) {
|
||||
ApiShared.LOGGER.info("Lightmap update");
|
||||
MinecraftRenderWrapper.INSTANCE.updateLightmap(lightPixels);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,8 @@
|
||||
"MixinChunkGenerator",
|
||||
"events.MixinClientLevel",
|
||||
"events.MixinMinecraft",
|
||||
"events.MixinBlockUpdate"
|
||||
"events.MixinBlockUpdate",
|
||||
"events.MixinLightmap"
|
||||
],
|
||||
"server": [
|
||||
"MixinDedicatedServer"
|
||||
|
||||
@@ -47,8 +47,8 @@ public class MixinFogRenderer
|
||||
{
|
||||
|
||||
// Using this instead of Float.MAX_VALUE because Sodium don't like it. (and copy paste in case someone in forge don't like it)
|
||||
private static final float A_REALLY_REALLY_BIG_VALUE = 4206942069.F;
|
||||
private static final float A_EVEN_LARGER_VALUE = 420694206942069.F;
|
||||
private static final float A_REALLY_REALLY_BIG_VALUE = 420694206942069.F;
|
||||
private static final float A_EVEN_LARGER_VALUE = 42069420694206942069.F;
|
||||
|
||||
@Inject(at = @At("RETURN"),
|
||||
method = "setupFog(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/FogRenderer$FogMode;FZF)V",
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.seibel.lod.forge.mixins;
|
||||
|
||||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.seibel.lod.common.wrappers.minecraft.MinecraftRenderWrapper;
|
||||
import com.seibel.lod.core.api.ApiShared;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(LightTexture.class)
|
||||
public class MixinLightmap {
|
||||
@Shadow
|
||||
@Final
|
||||
public NativeImage lightPixels;
|
||||
|
||||
@Inject(method="updateLightTexture", at=@At(
|
||||
value="INVOKE",
|
||||
target="Lnet/minecraft/client/renderer/texture/DynamicTexture;upload()V"))
|
||||
public void updateLightTexture(float f, CallbackInfo ci) {
|
||||
ApiShared.LOGGER.info("Lightmap update");
|
||||
MinecraftRenderWrapper.INSTANCE.updateLightmap(lightPixels);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@
|
||||
"MixinOptionsScreen",
|
||||
"MixinWorldRenderer",
|
||||
"MixinFogRenderer",
|
||||
"MixinChunkGenerator"
|
||||
"MixinChunkGenerator",
|
||||
"MixinLightmap"
|
||||
],
|
||||
"server": []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user