Add Dynamic Lights to Alpha (Module Off, Lights Off) (#465)

If a player is reading this and wants dynamic lights during alpha, please enable the module in the angelica-modules config file then the config option in the video settings will take effect.

* Implement Dynamic Lights (#360)

* inital dynamicLights

* continue work

* Add credit

* More implementations

* "Working"

* NotFine 0.2.2 sync (#462)

* Slight cleanup in ColorizeBlock

* Don't call System.gc

* Add toggle for Renderpass (forced to false)

* Dont rebuild the same chunk 8 times

* Use client pos

* Fully working + configs

* Clean up

* Fix readme and gradle properties

* Fix tooltip

* nit changes

---------

Co-authored-by: jss2a98aj <[email protected]>

* Might help if the dynamic lights mixins follow the config setting

* Fix shadows from showing on sides of blocks

* Set dynamic lights module to off for alpha

* Add missed enable checks

---------

Co-authored-by: jss2a98aj <[email protected]>
Co-authored-by: Jason Mitchell <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-05-06 00:19:50 +00:00
1 parent 894b9573db
commit 88d5030aa9
21 files changed
+821 -17

No files matched your search

@@ -221,6 +221,7 @@ public class SodiumGameOptionPages {
)*/
.add(Settings.MODE_SHADOWS.option)
.add(Settings.MODE_VIGNETTE.option)
.add(Settings.DYNAMIC_LIGHTS.option)
.build());
@@ -1,6 +1,8 @@
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;
import me.jellysquid.mods.sodium.client.world.WorldSlice;
import net.minecraft.block.Block;
@@ -119,6 +121,19 @@ public abstract class LightDataAccess {
return aoi * (1.0f / 4096.0f);
}
public static int getLightMap(long originWord, BlockPosImpl pos) {
if (!DynamicLights.isEnabled()) {
return unpackLM(originWord);
}
if (unpackFO(originWord)){
return unpackLM(originWord);
}
double dynamic = DynamicLights.get().getDynamicLightLevel(pos);
return DynamicLights.get().getLightmapWithDynamicLight(dynamic, unpackLM(originWord));
}
public WorldSlice getWorld() {
return this.world;
}
@@ -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.unpackLM(this.lightCache.get(pos));
lightmap = LightDataAccess.getLightMap(this.lightCache.get(pos), 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.unpackLM(this.lightCache.get(pos, face));
int lightmap = LightDataAccess.getLightMap(this.lightCache.get(pos, face), pos);
// If the block light is not 15 (max)...
if ((lightmap & 0xF0) != 0xF0) {
int originLightmap = LightDataAccess.unpackLM(this.lightCache.get(pos));
int originLightmap = LightDataAccess.getLightMap(this.lightCache.get(pos), pos);
// ...take the maximum combined block light at the origin and offset positions
lightmap = (lightmap & ~0xFF) | Math.max(lightmap & 0xFF, originLightmap & 0xFF);
}
@@ -6,8 +6,8 @@ import net.minecraftforge.common.util.ForgeDirection;
import static me.jellysquid.mods.sodium.client.model.light.cache.ArrayLightDataCache.unpackAO;
import static me.jellysquid.mods.sodium.client.model.light.cache.ArrayLightDataCache.unpackFO;
import static me.jellysquid.mods.sodium.client.model.light.cache.ArrayLightDataCache.unpackLM;
import static me.jellysquid.mods.sodium.client.model.light.cache.ArrayLightDataCache.unpackOP;
import static me.jellysquid.mods.sodium.client.model.light.cache.ArrayLightDataCache.getLightMap;
class AoFaceData {
public final int[] lm = new int[4];
@@ -43,9 +43,9 @@ class AoFaceData {
// Use the origin block's light values if the adjacent one is opaque
if (offset && unpackFO(adjWord)) {
calm = unpackLM(cache.get(x, y, z));
calm = getLightMap(cache.get(x, y, z), pos);
} else {
calm = unpackLM(adjWord);
calm = getLightMap(adjWord, pos);
}
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 = unpackLM(e0);
final int e0lm = getLightMap(e0, pos);
final float e0ao = unpackAO(e0);
final boolean e0op = unpackOP(e0);
final long e1 = cache.get(adjX, adjY, adjZ, faces[1]);
final int e1lm = unpackLM(e1);
final int e1lm = getLightMap(e1, pos);
final float e1ao = unpackAO(e1);
final boolean e1op = unpackOP(e1);
final long e2 = cache.get(adjX, adjY, adjZ, faces[2]);
final int e2lm = unpackLM(e2);
final int e2lm = getLightMap(e2, pos);
final float e2ao = unpackAO(e2);
final boolean e2op = unpackOP(e2);
final long e3 = cache.get(adjX, adjY, adjZ, faces[3]);
final int e3lm = unpackLM(e3);
final int e3lm = getLightMap(e3, pos);
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 = unpackLM(d0);
c0lm = getLightMap(d0, pos);
c0ao = unpackAO(d0);
}
@@ -93,7 +93,7 @@ class AoFaceData {
c1ao = e0ao;
} else {
long d1 = cache.get(adjX, adjY, adjZ, faces[0], faces[3]);
c1lm = unpackLM(d1);
c1lm = getLightMap(d1, pos);
c1ao = unpackAO(d1);
}
@@ -106,7 +106,7 @@ class AoFaceData {
c2ao = e1ao;
} else {
long d2 = cache.get(adjX, adjY, adjZ, faces[1], faces[2]);
c2lm = unpackLM(d2);
c2lm = getLightMap(d2, pos);
c2ao = unpackAO(d2);
}
@@ -119,7 +119,7 @@ class AoFaceData {
c3ao = e1ao;
} else {
long d3 = cache.get(adjX, adjY, adjZ, faces[1], faces[3]);
c3lm = unpackLM(d3);
c3lm = getLightMap(d3, pos);
c3ao = unpackAO(d3);
}
@@ -5,6 +5,7 @@ import com.gtnewhorizons.angelica.compat.mojang.ChunkPos;
import com.gtnewhorizons.angelica.compat.toremove.MatrixStack;
import com.gtnewhorizons.angelica.compat.toremove.RenderLayer;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import it.unimi.dsi.fastutil.longs.LongSet;
@@ -115,6 +116,9 @@ public class SodiumWorldRenderer implements ChunkStatusListener {
// If we have a world is already loaded, unload the renderer
if (this.world != null) {
if (DynamicLights.isEnabled()){
DynamicLights.get().clearLightSources();
}
this.unloadWorld();
}
@@ -122,6 +126,7 @@ public class SodiumWorldRenderer implements ChunkStatusListener {
if (world != null) {
this.loadWorld(world);
}
}
private void loadWorld(WorldClient world) {
@@ -4,6 +4,7 @@ import java.util.Arrays;
import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
import com.gtnewhorizons.angelica.compat.mojang.CompatMathHelper;
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
import lombok.Getter;
import me.jellysquid.mods.sodium.client.world.cloned.ChunkRenderContext;
import me.jellysquid.mods.sodium.client.world.cloned.ClonedChunkSection;
@@ -196,6 +197,10 @@ public class WorldSlice implements IBlockAccess {
blockBrightness = min;
}
if (DynamicLights.isEnabled() && !getBlock(x, y, z).isOpaqueCube()) {
return DynamicLights.get().getLightmapWithDynamicLight(x, y, z, (skyBrightness << 20 | blockBrightness << 4));
}
return skyBrightness << 20 | blockBrightness << 4;
}