Fix sodium smooth dynamic lights (#577)

This commit is contained in:
Caedis authored and GitHub committed 2024-07-31 16:13:15 -04:00
1 parent 29072ee3f8
commit e33f2ff7e3
6 files changed
+19 -18

No files matched your search

@@ -42,6 +42,7 @@ public class ArrayLightDataCache extends LightDataAccess {
@Override
public long get(int x, int y, int z) {
DynamicLightsPos.get().set(x, y, z);
int l = this.index(x, y, z);
long word = this.light[l];
@@ -18,6 +18,7 @@ public class HashLightDataCache extends LightDataAccess {
@Override
public long get(int x, int y, int z) {
DynamicLightsPos.get().set(x, y, z);
long key = BlockPos.asLong(x, y, z);
long word = this.map.getAndMoveToFirst(key);
@@ -1,6 +1,5 @@
package me.jellysquid.mods.sodium.client.model.light.data;
import com.gtnewhorizons.angelica.api.MutableBlockPos;
import com.gtnewhorizons.angelica.compat.mojang.BlockPosImpl;
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
import me.jellysquid.mods.sodium.client.util.StateUtil;
@@ -24,7 +23,7 @@ import net.minecraftforge.common.util.ForgeDirection;
* You can use the various static pack/unpack methods to extract these values in a usable format.
*/
public abstract class LightDataAccess {
private final BlockPosImpl pos = new BlockPosImpl();
public static final ThreadLocal<BlockPosImpl> DynamicLightsPos = ThreadLocal.withInitial(BlockPosImpl::new);
protected WorldSlice world;
public long get(int x, int y, int z, ForgeDirection d1, ForgeDirection d2) {
@@ -121,7 +120,7 @@ public abstract class LightDataAccess {
return aoi * (1.0f / 4096.0f);
}
public static int getLightMap(long originWord, BlockPosImpl pos) {
public static int getLightMap(long originWord) {
if (!DynamicLights.isEnabled()) {
return unpackLM(originWord);
}
@@ -129,7 +128,7 @@ public abstract class LightDataAccess {
return unpackLM(originWord);
}
double dynamic = DynamicLights.get().getDynamicLightLevel(pos);
double dynamic = DynamicLights.get().getDynamicLightLevel(DynamicLightsPos.get());
return DynamicLights.get().getLightmapWithDynamicLight(dynamic, unpackLM(originWord));
}
@@ -40,7 +40,7 @@ public class FlatLightPipeline implements LightPipeline {
if ((flags & ModelQuadFlags.IS_ALIGNED) != 0 || ((flags & ModelQuadFlags.IS_PARALLEL) != 0 && LightDataAccess.unpackFC(this.lightCache.get(pos)))) {
lightmap = getOffsetLightmap(pos, face);
} else {
lightmap = LightDataAccess.getLightMap(this.lightCache.get(pos), pos);
lightmap = LightDataAccess.getLightMap(this.lightCache.get(pos));
}
}
@@ -58,10 +58,10 @@ public class FlatLightPipeline implements LightPipeline {
* inconsistent values so this method exists to mirror vanilla behavior as closely as possible.
*/
private int getOffsetLightmap(BlockPosImpl pos, ForgeDirection face) {
int lightmap = LightDataAccess.getLightMap(this.lightCache.get(pos, face), pos);
int lightmap = LightDataAccess.getLightMap(this.lightCache.get(pos, face));
// If the block light is not 15 (max)...
if ((lightmap & 0xF0) != 0xF0) {
int originLightmap = LightDataAccess.getLightMap(this.lightCache.get(pos), pos);
int originLightmap = LightDataAccess.getLightMap(this.lightCache.get(pos));
// ...take the maximum combined block light at the origin and offset positions
lightmap = (lightmap & ~0xFF) | Math.max(lightmap & 0xFF, originLightmap & 0xFF);
}
@@ -43,9 +43,9 @@ class AoFaceData {
// Use the origin block's light values if the adjacent one is opaque
if (offset && unpackFO(adjWord)) {
calm = getLightMap(cache.get(x, y, z), pos);
calm = getLightMap(cache.get(x, y, z));
} else {
calm = getLightMap(adjWord, pos);
calm = getLightMap(adjWord);
}
final float caao = unpackAO(adjWord);
@@ -53,22 +53,22 @@ class AoFaceData {
ForgeDirection[] faces = AoNeighborInfo.get(direction).faces;
final long e0 = cache.get(adjX, adjY, adjZ, faces[0]);
final int e0lm = getLightMap(e0, pos);
final int e0lm = getLightMap(e0);
final float e0ao = unpackAO(e0);
final boolean e0op = unpackOP(e0);
final long e1 = cache.get(adjX, adjY, adjZ, faces[1]);
final int e1lm = getLightMap(e1, pos);
final int e1lm = getLightMap(e1);
final float e1ao = unpackAO(e1);
final boolean e1op = unpackOP(e1);
final long e2 = cache.get(adjX, adjY, adjZ, faces[2]);
final int e2lm = getLightMap(e2, pos);
final int e2lm = getLightMap(e2);
final float e2ao = unpackAO(e2);
final boolean e2op = unpackOP(e2);
final long e3 = cache.get(adjX, adjY, adjZ, faces[3]);
final int e3lm = getLightMap(e3, pos);
final int e3lm = getLightMap(e3);
final float e3ao = unpackAO(e3);
final boolean e3op = unpackOP(e3);
@@ -81,7 +81,7 @@ class AoFaceData {
c0ao = e0ao;
} else {
long d0 = cache.get(adjX, adjY, adjZ, faces[0], faces[2]);
c0lm = getLightMap(d0, pos);
c0lm = getLightMap(d0);
c0ao = unpackAO(d0);
}
@@ -93,7 +93,7 @@ class AoFaceData {
c1ao = e0ao;
} else {
long d1 = cache.get(adjX, adjY, adjZ, faces[0], faces[3]);
c1lm = getLightMap(d1, pos);
c1lm = getLightMap(d1);
c1ao = unpackAO(d1);
}
@@ -106,7 +106,7 @@ class AoFaceData {
c2ao = e1ao;
} else {
long d2 = cache.get(adjX, adjY, adjZ, faces[1], faces[2]);
c2lm = getLightMap(d2, pos);
c2lm = getLightMap(d2);
c2ao = unpackAO(d2);
}
@@ -119,7 +119,7 @@ class AoFaceData {
c3ao = e1ao;
} else {
long d3 = cache.get(adjX, adjY, adjZ, faces[1], faces[3]);
c3lm = getLightMap(d3, pos);
c3lm = getLightMap(d3);
c3ao = unpackAO(d3);
}
@@ -3,7 +3,6 @@ package me.jellysquid.mods.sodium.client.model.light.smooth;
import com.google.common.math.DoubleMath;
import com.gtnewhorizons.angelica.compat.mojang.BlockPosImpl;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import me.jellysquid.mods.sodium.client.SodiumClientMod;
import me.jellysquid.mods.sodium.client.model.light.LightPipeline;
import me.jellysquid.mods.sodium.client.model.light.data.LightDataAccess;
import me.jellysquid.mods.sodium.client.model.light.data.QuadLightData;
@@ -243,6 +242,7 @@ public class SmoothLightPipeline implements LightPipeline {
* Returns the cached data for a given facing or calculates it if it hasn't been cached.
*/
private AoFaceData getCachedFaceData(BlockPosImpl pos, ForgeDirection face, boolean offset) {
final AoFaceData data = this.cachedFaceData[offset ? face.ordinal() : face.ordinal() + 6];
if (!data.hasLightData()) {