diff --git a/build.gradle b/build.gradle index 36053f7a1..6caf08ab3 100644 --- a/build.gradle +++ b/build.gradle @@ -76,8 +76,9 @@ dependencies { testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1' minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" - compileOnly fg.deobf("maven.modrinth:embeddium:0.2.10+mc1.20.1") - compileOnly fg.deobf("maven.modrinth:oculus:1.20.1-1.6.9") + compileOnly fg.deobf("maven.modrinth:embeddium:0.3.9+mc1.20.1") + compileOnly fg.deobf("maven.modrinth:oculus:1.20.1-1.6.15a") + // implementation fg.deobf("maven.modrinth:starlight-forge:1.1.2+1.20") // https://discord.com/channels/313125603924639766/725850371834118214/910619168821354497 // Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/embed/AbstractEmbeddedEnvironment.java b/src/main/java/com/jozufozu/flywheel/backend/engine/embed/AbstractEmbeddedEnvironment.java index 03ecd9441..dda0f6a92 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/embed/AbstractEmbeddedEnvironment.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/embed/AbstractEmbeddedEnvironment.java @@ -61,15 +61,15 @@ public abstract class AbstractEmbeddedEnvironment extends AtomicReferenceCounted public void setupDraw(GlProgram program) { setupLight(program); - program.setMat4("_flw_modelMatrix", poseComposed); - program.setMat3("_flw_normalMatrix", normalComposed); + program.setMat4(EmbeddingUniforms.MODEL_MATRIX, poseComposed); + program.setMat3(EmbeddingUniforms.NORMAL_MATRIX, normalComposed); } @Override public void setupCull(GlProgram program) { - program.setBool("_flw_useModelMatrix", true); + program.setBool(EmbeddingUniforms.USE_MODEL_MATRIX, true); - program.setMat4("_flw_modelMatrix", poseComposed); + program.setMat4(EmbeddingUniforms.MODEL_MATRIX1, poseComposed); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/embed/EmbeddingUniforms.java b/src/main/java/com/jozufozu/flywheel/backend/engine/embed/EmbeddingUniforms.java new file mode 100644 index 000000000..3d31f8e94 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/embed/EmbeddingUniforms.java @@ -0,0 +1,11 @@ +package com.jozufozu.flywheel.backend.engine.embed; + +public class EmbeddingUniforms { + public static final String MODEL_MATRIX = "_flw_modelMatrix"; + public static final String NORMAL_MATRIX = "_flw_normalMatrix"; + public static final String USE_MODEL_MATRIX = "_flw_useModelMatrix"; + public static final String MODEL_MATRIX1 = "_flw_modelMatrix"; + public static final String ONE_OVER_LIGHT_BOX_SIZE = "_flw_oneOverLightBoxSize"; + public static final String LIGHT_VOLUME_MIN = "_flw_lightVolumeMin"; + public static final String USE_LIGHT_VOLUME = "_flw_useLightVolume"; +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/embed/GlobalEnvironment.java b/src/main/java/com/jozufozu/flywheel/backend/engine/embed/GlobalEnvironment.java index 6d7fbc987..72be0a05d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/embed/GlobalEnvironment.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/embed/GlobalEnvironment.java @@ -21,7 +21,7 @@ public class GlobalEnvironment implements Environment { @Override public void setupCull(GlProgram cullProgram) { - cullProgram.setBool("_flw_useEmbeddedModel", false); + cullProgram.setBool(EmbeddingUniforms.USE_MODEL_MATRIX, false); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/embed/TopLevelEmbeddedEnvironment.java b/src/main/java/com/jozufozu/flywheel/backend/engine/embed/TopLevelEmbeddedEnvironment.java index 451563d2f..d320acc3d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/embed/TopLevelEmbeddedEnvironment.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/embed/TopLevelEmbeddedEnvironment.java @@ -34,7 +34,6 @@ public class TopLevelEmbeddedEnvironment extends AbstractEmbeddedEnvironment { lightTexture.upload(lightVolume.ptr(), lightVolume.sizeX(), lightVolume.sizeY(), lightVolume.sizeZ()); } - @Override public void collectLight(BlockAndTintGetter level, int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ) { lightVolume.collect(level, minX, minY, minZ, sizeX, sizeY, sizeZ); @@ -56,11 +55,11 @@ public class TopLevelEmbeddedEnvironment extends AbstractEmbeddedEnvironment { float oneOverSizeY = 1f / (float) lightTexture.sizeY; float oneOverSizeZ = 1f / (float) lightTexture.sizeZ; - program.setVec3("_flw_oneOverLightBoxSize", oneOverSizeX, oneOverSizeY, oneOverSizeZ); - program.setVec3("_flw_lightVolumeMin", lightVolume.x(), lightVolume.y(), lightVolume.z()); - program.setBool("_flw_useLightVolume", true); + program.setVec3(EmbeddingUniforms.ONE_OVER_LIGHT_BOX_SIZE, oneOverSizeX, oneOverSizeY, oneOverSizeZ); + program.setVec3(EmbeddingUniforms.LIGHT_VOLUME_MIN, lightVolume.x(), lightVolume.y(), lightVolume.z()); + program.setBool(EmbeddingUniforms.USE_LIGHT_VOLUME, true); } else { - program.setBool("_flw_useLightVolume", false); + program.setBool(EmbeddingUniforms.USE_LIGHT_VOLUME, false); } } diff --git a/src/main/java/com/jozufozu/flywheel/impl/mixin/ClientChunkCacheMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/ClientChunkCacheMixin.java new file mode 100644 index 000000000..4cf130204 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/ClientChunkCacheMixin.java @@ -0,0 +1,31 @@ +package com.jozufozu.flywheel.impl.mixin; + +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; + +import com.jozufozu.flywheel.impl.visualization.VisualizationManagerImpl; + +import net.minecraft.client.multiplayer.ClientChunkCache; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.core.SectionPos; +import net.minecraft.world.level.LightLayer; + +@Mixin(ClientChunkCache.class) +public class ClientChunkCacheMixin { + @Shadow + @Final + ClientLevel level; + + @Inject(at = @At("HEAD"), method = "onLightUpdate") + private void flywheel$onLightUpdate(LightLayer pType, SectionPos pPos, CallbackInfo ci) { + var manager = VisualizationManagerImpl.get(level); + + if (manager != null) { + manager.enqueueLightUpdateSection(pPos.asLong()); + } + } +} diff --git a/src/main/java/com/jozufozu/flywheel/impl/mixin/LayerLightSectionStorageMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/LayerLightSectionStorageMixin.java deleted file mode 100644 index e16a24d24..000000000 --- a/src/main/java/com/jozufozu/flywheel/impl/mixin/LayerLightSectionStorageMixin.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.jozufozu.flywheel.impl.mixin; - -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; - -import com.jozufozu.flywheel.impl.visualization.VisualizationManagerImpl; - -import it.unimi.dsi.fastutil.longs.LongSet; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.chunk.LightChunkGetter; -import net.minecraft.world.level.lighting.LayerLightSectionStorage; - -@Mixin(LayerLightSectionStorage.class) -abstract class LayerLightSectionStorageMixin { - @Shadow - @Final - protected LightChunkGetter chunkSource; - @Shadow - @Final - protected LongSet sectionsAffectedByLightUpdates; - - @Inject(method = "swapSectionMap()V", at = @At("HEAD")) - private void flywheel$listenForChangedSections(CallbackInfo ci) { - if (sectionsAffectedByLightUpdates.isEmpty()) { - return; - } - - if (!(chunkSource.getLevel() instanceof LevelAccessor level)) { - return; - } - - var manager = VisualizationManagerImpl.get(level); - - if (manager != null) { - manager.enqueueLightUpdateSections(sectionsAffectedByLightUpdates); - } - } -} diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java index 80bfa9851..a53e0ff37 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java +++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java @@ -48,7 +48,6 @@ import com.jozufozu.flywheel.lib.task.SimplePlan; import com.jozufozu.flywheel.lib.util.LevelAttached; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; -import it.unimi.dsi.fastutil.longs.LongSet; import net.minecraft.client.Minecraft; import net.minecraft.core.Vec3i; import net.minecraft.server.level.BlockDestructionProgress; @@ -317,12 +316,12 @@ public class VisualizationManagerImpl implements VisualizationManager { engine.delete(); } - public void enqueueLightUpdateSections(LongSet sections) { + public void enqueueLightUpdateSection(long section) { blockEntities.getStorage() - .enqueueLightUpdateSections(sections); + .enqueueLightUpdateSection(section); entities.getStorage() - .enqueueLightUpdateSections(sections); + .enqueueLightUpdateSection(section); effects.getStorage() - .enqueueLightUpdateSections(sections); + .enqueueLightUpdateSection(section); } } diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/LitVisualStorage.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/LitVisualStorage.java index 166f7dadb..ca1c773a1 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/LitVisualStorage.java +++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/LitVisualStorage.java @@ -116,8 +116,8 @@ public class LitVisualStorage { } } - public void enqueueLightUpdateSections(LongSet sections) { - sectionsUpdatedThisFrame.addAll(sections); + public void enqueueLightUpdateSection(long section) { + sectionsUpdatedThisFrame.add(section); } /** diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/Storage.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/Storage.java index 69e31fc54..f90a189e8 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/Storage.java +++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/Storage.java @@ -22,7 +22,6 @@ import com.jozufozu.flywheel.lib.task.PlanMap; import com.jozufozu.flywheel.lib.visual.SimpleDynamicVisual; import com.jozufozu.flywheel.lib.visual.SimpleTickableVisual; -import it.unimi.dsi.fastutil.longs.LongSet; import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; public abstract class Storage { @@ -144,8 +143,8 @@ public abstract class Storage { return NestedPlan.of(tickableVisuals, ForEachPlan.of(() -> simpleTickableVisuals, SimpleTickableVisual::tick)); } - public void enqueueLightUpdateSections(LongSet sections) { - litVisuals.enqueueLightUpdateSections(sections); + public void enqueueLightUpdateSection(long section) { + litVisuals.enqueueLightUpdateSection(section); } private void setup(Visual visual, float partialTick) { diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java index c27a5f817..8c7f8d8a5 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java @@ -70,6 +70,7 @@ public class MinecartVisual extends SimpleEntityVisu contents = createContentsInstance(); updateInstances(partialTick); + updateLight(); super.init(partialTick); } diff --git a/src/main/resources/flywheel.impl.mixins.json b/src/main/resources/flywheel.impl.mixins.json index 47b52454b..545e99a3a 100644 --- a/src/main/resources/flywheel.impl.mixins.json +++ b/src/main/resources/flywheel.impl.mixins.json @@ -6,9 +6,9 @@ "refmap": "flywheel.refmap.json", "client": [ "BlockEntityTypeMixin", + "ClientChunkCacheMixin", "ClientLevelMixin", "EntityTypeMixin", - "LayerLightSectionStorageMixin", "LevelMixin", "LevelRendererMixin", "MinecraftMixin",