From a0b0e6788de80d8facc094e88bac230fd65e42a7 Mon Sep 17 00:00:00 2001 From: tterrag Date: Thu, 2 Jul 2020 01:42:01 -0400 Subject: [PATCH] Fix improper handling of baked lighting in forge light pipeline Closes #6812 --- .../client/model/pipeline/VertexLighterFlat.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minecraftforge/client/model/pipeline/VertexLighterFlat.java b/src/main/java/net/minecraftforge/client/model/pipeline/VertexLighterFlat.java index a378fb5039..1681ed5a39 100644 --- a/src/main/java/net/minecraftforge/client/model/pipeline/VertexLighterFlat.java +++ b/src/main/java/net/minecraftforge/client/model/pipeline/VertexLighterFlat.java @@ -19,6 +19,9 @@ package net.minecraftforge.client.model.pipeline; +import java.util.List; +import java.util.Objects; + import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.mojang.blaze3d.matrix.MatrixStack; @@ -36,12 +39,17 @@ import net.minecraft.util.math.vector.Vector3f; import net.minecraft.util.math.vector.Vector4f; import net.minecraft.world.IBlockDisplayReader; -import java.util.List; -import java.util.Objects; - public class VertexLighterFlat extends QuadGatheringTransformer { protected static final VertexFormatElement NORMAL_4F = new VertexFormatElement(0, VertexFormatElement.Type.FLOAT, VertexFormatElement.Usage.NORMAL, 4); + + // TODO 1.16/1.17 possibly refactor out the need for the "unpacked" format entirely. It's creating more headaches than solutions. + // This mess reverses the conversion to float bits done in LightUtil.unpack + private static final int LIGHTMAP_PACKING_FACTOR = ((256 << (8 * (DefaultVertexFormats.TEX_2SB.getType().getSize() - 1))) - 1) >>> 1; + // Max lightmap value, for rescaling + private static final int LIGHTMAP_MAX = 0xF0; + // Inlined factor for rescaling input lightmap values, "rounded" up to the next float value to avoid precision loss when result is truncated to int + private static final float LIGHTMAP_RESCALE = Math.nextAfter((float) LIGHTMAP_PACKING_FACTOR / LIGHTMAP_MAX, LIGHTMAP_PACKING_FACTOR); protected final BlockInfo blockInfo; private int tint = -1; @@ -197,7 +205,7 @@ public class VertexLighterFlat extends QuadGatheringTransformer z += normal[v][2] * .5f; } - float blockLight = lightmap[v][0], skyLight = lightmap[v][1]; + float blockLight = lightmap[v][0] * LIGHTMAP_RESCALE, skyLight = lightmap[v][1] * LIGHTMAP_RESCALE; updateLightmap(normal[v], lightmap[v], x, y, z); if(dataLength[lightmapIndex] > 1) {