diff --git a/src/main/java/net/coderbot/iris/gbuffer_overrides/matching/RenderCondition.java b/src/main/java/net/coderbot/iris/gbuffer_overrides/matching/RenderCondition.java index d9168e63f..813c8c4e7 100644 --- a/src/main/java/net/coderbot/iris/gbuffer_overrides/matching/RenderCondition.java +++ b/src/main/java/net/coderbot/iris/gbuffer_overrides/matching/RenderCondition.java @@ -18,6 +18,7 @@ public enum RenderCondition { HAND_TRANSLUCENT, RAIN_SNOW, WORLD_BORDER, + LIGHTNING, SHADOW_TRANSLUCENT, // NB: Must be last due to implementation details of DeferredWorldRenderingPipeline SHADOW diff --git a/src/main/java/net/coderbot/iris/gbuffer_overrides/matching/SpecialCondition.java b/src/main/java/net/coderbot/iris/gbuffer_overrides/matching/SpecialCondition.java index deeb20933..5454e8390 100644 --- a/src/main/java/net/coderbot/iris/gbuffer_overrides/matching/SpecialCondition.java +++ b/src/main/java/net/coderbot/iris/gbuffer_overrides/matching/SpecialCondition.java @@ -3,5 +3,6 @@ package net.coderbot.iris.gbuffer_overrides.matching; public enum SpecialCondition { ENTITY_EYES, BEACON_BEAM, - GLINT + GLINT, + LIGHTNING } diff --git a/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java b/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java index 53cdd8718..82b3c3f6e 100644 --- a/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java +++ b/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java @@ -395,6 +395,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R null, null, ProgramId.Weather, // world border uses textured_lit even though it has no lightmap :/ null, ProgramId.TexturedLit, ProgramId.TexturedLit, + ProgramId.Lightning, ProgramId.Lightning, ProgramId.Lightning, ProgramId.ShadowWater, ProgramId.ShadowWater, ProgramId.ShadowWater, ProgramId.Shadow, ProgramId.Shadow, ProgramId.Shadow }; @@ -724,6 +725,8 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R return RenderCondition.ENTITY_EYES; } else if (special == SpecialCondition.GLINT) { return RenderCondition.GLINT; + } else if (special == SpecialCondition.LIGHTNING) { + return RenderCondition.LIGHTNING; } } diff --git a/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java b/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java index 6ff7b8dc1..2fe6b12db 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java @@ -41,6 +41,7 @@ public class ProgramSet { private final ProgramSource gbuffersEntities; private final ProgramSource gbuffersEntitiesTrans; private final ProgramSource gbuffersEntitiesGlowing; + private final ProgramSource gbuffersLightning; private final ProgramSource gbuffersGlint; private final ProgramSource gbuffersEntityEyes; private final ProgramSource gbuffersBlock; @@ -120,6 +121,7 @@ public class ProgramSet { this.gbuffersEntities = readProgramSource(directory, sourceProvider, "gbuffers_entities", this, shaderProperties); this.gbuffersEntitiesTrans = readProgramSource(directory, sourceProvider, "gbuffers_entities_translucent", this, shaderProperties); this.gbuffersEntitiesGlowing = readProgramSource(directory, sourceProvider, "gbuffers_entities_glowing", this, shaderProperties); + this.gbuffersLightning = readProgramSource(directory, sourceProvider, "gbuffers_lightning", this, shaderProperties); this.gbuffersGlint = readProgramSource(directory, sourceProvider, "gbuffers_armor_glint", this, shaderProperties); this.gbuffersEntityEyes = readProgramSource(directory, sourceProvider, "gbuffers_spidereyes", this, shaderProperties); this.gbuffersBlock = readProgramSource(directory, sourceProvider, "gbuffers_block", this, shaderProperties); @@ -229,7 +231,7 @@ public class ProgramSet { programs.addAll (Arrays.asList( gbuffersBasic, gbuffersBeaconBeam, gbuffersTextured, gbuffersTexturedLit, gbuffersTerrain, gbuffersDamagedBlock, gbuffersSkyBasic, gbuffersSkyTextured, gbuffersClouds, gbuffersWeather, - gbuffersEntities, gbuffersEntitiesTrans, gbuffersEntitiesGlowing, gbuffersGlint, gbuffersEntityEyes, gbuffersBlock, gbuffersBlockTrans, + gbuffersEntities, gbuffersEntitiesTrans, gbuffersEntitiesGlowing, gbuffersLightning, gbuffersGlint, gbuffersEntityEyes, gbuffersBlock, gbuffersBlockTrans, gbuffersHand, dhShadow, dhTerrain, dhGeneric, dhWater )); @@ -382,6 +384,10 @@ public class ProgramSet { return gbuffersEntitiesGlowing.requireValid(); } + public Optional getGbuffersLightning() { + return gbuffersLightning.requireValid(); + } + public Optional getGbuffersGlint() { return gbuffersGlint.requireValid(); } @@ -437,6 +443,7 @@ public class ProgramSet { case Entities -> getGbuffersEntities(); case EntitiesTrans -> getGbuffersEntitiesTrans(); case EntitiesGlowing -> getGbuffersEntitiesGlowing(); + case Lightning -> getGbuffersLightning(); case ArmorGlint -> getGbuffersGlint(); case SpiderEyes -> getGbuffersEntityEyes(); case Hand -> getGbuffersHand(); diff --git a/src/main/java/net/coderbot/iris/shaderpack/loading/ProgramId.java b/src/main/java/net/coderbot/iris/shaderpack/loading/ProgramId.java index 28b7e60e9..ed405387b 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/loading/ProgramId.java +++ b/src/main/java/net/coderbot/iris/shaderpack/loading/ProgramId.java @@ -39,6 +39,7 @@ public enum ProgramId { Entities(ProgramGroup.Gbuffers, "entities", TexturedLit), EntitiesTrans(ProgramGroup.Gbuffers, "entities_translucent", Entities), EntitiesGlowing(ProgramGroup.Gbuffers, "entities_glowing", Entities), + Lightning(ProgramGroup.Gbuffers, "lightning", Entities), ArmorGlint(ProgramGroup.Gbuffers, "armor_glint", Textured), SpiderEyes(ProgramGroup.Gbuffers, "spidereyes", Textured, new BlendModeOverride(new BlendState(GL11.GL_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO, GL11.GL_ONE)), diff --git a/src/main/java/net/coderbot/iris/uniforms/EntityIdHelper.java b/src/main/java/net/coderbot/iris/uniforms/EntityIdHelper.java index 87b9d9130..02c51ee46 100644 --- a/src/main/java/net/coderbot/iris/uniforms/EntityIdHelper.java +++ b/src/main/java/net/coderbot/iris/uniforms/EntityIdHelper.java @@ -42,6 +42,10 @@ public final class EntityIdHelper { private EntityIdHelper() { } + public static boolean isLightningBolt(Entity entity) { + return entity instanceof EntityLightningBolt; + } + /** * Get the entity ID for the given entity. * diff --git a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderDragon.java b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderDragon.java index 7902ca400..796fcb8ba 100644 --- a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderDragon.java +++ b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderDragon.java @@ -1,29 +1,45 @@ package com.gtnewhorizons.angelica.mixins.early.shaders; +import com.gtnewhorizons.angelica.glsm.GLStateManager; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import it.unimi.dsi.fastutil.objects.Object2IntFunction; import net.coderbot.iris.block_rendering.BlockRenderingSettings; +import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition; +import net.coderbot.iris.layer.GbufferPrograms; import net.coderbot.iris.shaderpack.materialmap.NamespacedId; import net.coderbot.iris.uniforms.CapturedRenderingState; import net.minecraft.client.renderer.entity.RenderDragon; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.boss.EntityDragon; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.gen.Invoker; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; /** - * Mixin to set the entity ID to "end_crystal_beam" when rendering ender dragon healing beams. - * This allows shaders to apply special effects to the healing beams separately from the dragon itself. + * Mixin allows devs to target the ender crystal beams as a separate entity. + * Also sets the special condition "lightning" on the dragon's death beams. */ @Mixin(RenderDragon.class) -public class MixinRenderDragon { +public abstract class MixinRenderDragon { @Unique private static final NamespacedId END_CRYSTAL_BEAM = new NamespacedId("minecraft", "end_crystal_beam"); @Unique private int angelica$previousEntityId = -1; + @Unique + private boolean angelica$deathBeamsActive = false; + + @Unique + private int angelica$depthPassReplay = 0; + + @Invoker("renderEquippedItems") + protected abstract void angelica$invokeRenderEquippedItems(EntityDragon dragon, float partialTicks); + @Inject( method = "doRender(Lnet/minecraft/entity/boss/EntityDragon;DDDFF)V", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glPushMatrix()V", ordinal = 0, shift = At.Shift.AFTER, remap = false) @@ -52,4 +68,58 @@ public class MixinRenderDragon { angelica$previousEntityId = -1; } } + + /** + * We adapt the 2 pass structure that Modern Iris uses for the death beams. + * Replay like this so mixins that target the vanilla code hopefully runs too. + *

+ * Pass 1: Write the depth buffer. + * Pass 2: Write color. + */ + @Inject(method = "renderEquippedItems(Lnet/minecraft/entity/boss/EntityDragon;F)V", at = @At("HEAD")) + private void angelica$beginDeathBeamsLightningBuffer(EntityDragon dragon, float partialTicks, CallbackInfo ci) { + if (angelica$depthPassReplay > 0) return; + if (dragon.deathTicks > 0) { + GbufferPrograms.setupSpecialRenderCondition(SpecialCondition.LIGHTNING); + angelica$deathBeamsActive = true; + + angelica$depthPassReplay++; + GLStateManager.glColorMask(false, false, false, false); + angelica$invokeRenderEquippedItems(dragon, partialTicks); + GLStateManager.glColorMask(true, true, true, true); + angelica$depthPassReplay--; + } + } + + // Don't render items twice + @WrapOperation( + method = "renderEquippedItems(Lnet/minecraft/entity/boss/EntityDragon;F)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderLiving;renderEquippedItems(Lnet/minecraft/entity/EntityLivingBase;F)V") + ) + private void angelica$skipSuperDuringReplay(RenderDragon self, EntityLivingBase entity, float partialTicks, Operation original) { + if (angelica$depthPassReplay == 0) { + original.call(self, entity, partialTicks); + } + } + + // No-op the depth buffer being set to false on first pass + @WrapOperation( + method = "renderEquippedItems(Lnet/minecraft/entity/boss/EntityDragon;F)V", + at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDepthMask(Z)V", ordinal = 0, remap = false) + ) + private void angelica$keepDepthMaskDuringReplay(boolean flag, Operation original) { + if (angelica$depthPassReplay == 0) { + original.call(flag); + } + } + + // End replay + @Inject(method = "renderEquippedItems(Lnet/minecraft/entity/boss/EntityDragon;F)V", at = @At("RETURN")) + private void angelica$endDeathBeamsLighting(EntityDragon dragon, float partialTicks, CallbackInfo ci) { + if (angelica$depthPassReplay > 0) return; + if (angelica$deathBeamsActive) { + GbufferPrograms.teardownSpecialRenderCondition(); + angelica$deathBeamsActive = false; + } + } } diff --git a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderManager.java b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderManager.java index b4f47adf8..51dbd85a8 100644 --- a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderManager.java +++ b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderManager.java @@ -2,6 +2,8 @@ package com.gtnewhorizons.angelica.mixins.early.shaders; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition; +import net.coderbot.iris.layer.GbufferPrograms; import net.coderbot.iris.uniforms.CapturedRenderingState; import net.coderbot.iris.uniforms.EntityIdHelper; import net.minecraft.client.renderer.entity.Render; @@ -25,7 +27,14 @@ public class MixinRenderManager { private void iris$wrapDoRender(Render render, Entity entity, double x, double y, double z, float entityYaw, float partialTicks, Operation original) { int entityId = EntityIdHelper.getEntityId(entity); CapturedRenderingState.INSTANCE.setCurrentEntity(entityId); + final boolean lightning = EntityIdHelper.isLightningBolt(entity); + if (lightning) { + GbufferPrograms.setupSpecialRenderCondition(SpecialCondition.LIGHTNING); + } original.call(render, entity, x, y, z, entityYaw, partialTicks); + if (lightning) { + GbufferPrograms.teardownSpecialRenderCondition(); + } CapturedRenderingState.INSTANCE.setCurrentEntity(-1); } } diff --git a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderManagerDAPI.java b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderManagerDAPI.java index 1fdc4768a..343bcff93 100644 --- a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderManagerDAPI.java +++ b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderManagerDAPI.java @@ -2,6 +2,8 @@ package com.gtnewhorizons.angelica.mixins.early.shaders; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition; +import net.coderbot.iris.layer.GbufferPrograms; import net.coderbot.iris.uniforms.CapturedRenderingState; import net.coderbot.iris.uniforms.EntityIdHelper; import net.minecraft.client.renderer.entity.Render; @@ -23,7 +25,14 @@ public class MixinRenderManagerDAPI { private void iris$wrapDoRenderDragonAPI(Render render, Entity entity, double x, double y, double z, float entityYaw, float partialTicks, Operation original) { int entityId = EntityIdHelper.getEntityId(entity); CapturedRenderingState.INSTANCE.setCurrentEntity(entityId); + final boolean lightning = EntityIdHelper.isLightningBolt(entity); + if (lightning) { + GbufferPrograms.setupSpecialRenderCondition(SpecialCondition.LIGHTNING); + } original.call(render, entity, x, y, z, entityYaw, partialTicks); + if (lightning) { + GbufferPrograms.teardownSpecialRenderCondition(); + } CapturedRenderingState.INSTANCE.setCurrentEntity(-1); } }