From 30e1eb5f130ff91c109ac1c77d2631a48afea73a Mon Sep 17 00:00:00 2001 From: KostromDan Date: Mon, 11 Nov 2024 03:25:05 +0300 Subject: [PATCH] Mekasuit render fix backport. fixes https://github.com/Asek3/Oculus/issues/170 --- .../MixinRenderFlame.java | 37 +++++++++++++++++++ .../MixinRenderMekasuit.java | 36 ++++++++++++++++++ .../iris/pathways/LightningHandler.java | 23 ++++++++++++ .../iris/pipeline/programs/ShaderAccess.java | 17 +++++++++ .../iris/pipeline/programs/ShaderKey.java | 4 +- .../iris/shaderpack/loading/ProgramId.java | 1 + src/main/resources/mixins.oculus.json | 2 + 7 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/irisshaders/iris/mixin/entity_render_context/MixinRenderFlame.java create mode 100644 src/main/java/net/irisshaders/iris/mixin/entity_render_context/MixinRenderMekasuit.java diff --git a/src/main/java/net/irisshaders/iris/mixin/entity_render_context/MixinRenderFlame.java b/src/main/java/net/irisshaders/iris/mixin/entity_render_context/MixinRenderFlame.java new file mode 100644 index 0000000000..4ebb790f35 --- /dev/null +++ b/src/main/java/net/irisshaders/iris/mixin/entity_render_context/MixinRenderFlame.java @@ -0,0 +1,37 @@ +package net.irisshaders.iris.mixin.entity_render_context; + +import net.irisshaders.iris.Iris; +import net.irisshaders.iris.pathways.LightningHandler; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.resources.ResourceLocation; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.function.Function; + +@Pseudo +@Mixin(targets = "mekanism/client/render/entity/RenderFlame", remap = false) +public class MixinRenderFlame { + private static Object MEKANISM_FLAME; + + static { + try { + MEKANISM_FLAME = Class.forName("mekanism.client.render.MekanismRenderType").getField("FLAME").get(null); + } catch (IllegalAccessException | NoSuchFieldException | ClassNotFoundException e) { + Iris.logger.fatal("Failed to get Mekanism flame!"); + } + } + + @Redirect(method = { + "render(Lmekanism/common/entity/EntityFlame;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V" + }, at = @At(value = "FIELD", target = "Lmekanism/client/render/MekanismRenderType;FLAME:Ljava/util/function/Function;")) + private Function doNotSwitchShaders() { + if (Iris.isPackInUseQuick()) { + return LightningHandler.MEKANISM_FLAME; + } else { + return (Function) MEKANISM_FLAME; + } + } +} diff --git a/src/main/java/net/irisshaders/iris/mixin/entity_render_context/MixinRenderMekasuit.java b/src/main/java/net/irisshaders/iris/mixin/entity_render_context/MixinRenderMekasuit.java new file mode 100644 index 0000000000..6544d018a3 --- /dev/null +++ b/src/main/java/net/irisshaders/iris/mixin/entity_render_context/MixinRenderMekasuit.java @@ -0,0 +1,36 @@ +package net.irisshaders.iris.mixin.entity_render_context; + +import net.irisshaders.iris.Iris; +import net.irisshaders.iris.pathways.LightningHandler; +import net.irisshaders.iris.vertices.ImmediateState; +import net.minecraft.client.renderer.RenderType; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Pseudo +@Mixin(targets = "mekanism/client/render/armor/MekaSuitArmor", remap = false) +public class MixinRenderMekasuit { + private static Object MEKASUIT; + + static { + try { + MEKASUIT = Class.forName("mekanism.client.render.MekanismRenderType").getField("MEKASUIT").get(null); + } catch (IllegalAccessException | NoSuchFieldException | ClassNotFoundException e) { + Iris.logger.fatal("Failed to get Mekanism flame!"); + } + } + + @Redirect(method = { + "renderArm", + "Lmekanism/client/render/armor/MekaSuitArmor;render(Lnet/minecraft/client/model/HumanoidModel;Lnet/minecraft/client/renderer/MultiBufferSource;Lcom/mojang/blaze3d/vertex/PoseStack;IILmekanism/common/lib/Color;ZLnet/minecraft/world/entity/LivingEntity;Ljava/util/Map;Z)V" + }, at = @At(value = "FIELD", target = "Lmekanism/client/render/MekanismRenderType;MEKASUIT:Lnet/minecraft/client/renderer/RenderType;")) + private RenderType doNotSwitchShaders() { + if (Iris.isPackInUseQuick() && ImmediateState.isRenderingLevel) { + return LightningHandler.MEKASUIT; + } else { + return (RenderType) MEKASUIT; + } + } +} diff --git a/src/main/java/net/irisshaders/iris/pathways/LightningHandler.java b/src/main/java/net/irisshaders/iris/pathways/LightningHandler.java index c55a1de12e..967d81041b 100644 --- a/src/main/java/net/irisshaders/iris/pathways/LightningHandler.java +++ b/src/main/java/net/irisshaders/iris/pathways/LightningHandler.java @@ -4,7 +4,13 @@ import com.mojang.blaze3d.vertex.VertexFormat; import net.irisshaders.iris.layer.InnerWrappedRenderType; import net.irisshaders.iris.layer.LightningRenderStateShard; +import net.irisshaders.iris.pipeline.programs.ShaderAccess; +import net.minecraft.Util; +import net.minecraft.client.renderer.RenderStateShard; import net.minecraft.client.renderer.RenderType; +import net.minecraft.resources.ResourceLocation; + +import java.util.function.Function; public class LightningHandler extends RenderType { public static final RenderType IRIS_LIGHTNING = new InnerWrappedRenderType("iris_lightning2", RenderType.create( @@ -22,6 +28,23 @@ public class LightningHandler extends RenderType { .createCompositeState(false) ), new LightningRenderStateShard()); + public static final Function MEKANISM_FLAME = Util.memoize(resourceLocation -> { + RenderType.CompositeState state = RenderType.CompositeState.builder() + .setShaderState(new ShaderStateShard(ShaderAccess::getMekanismFlameShader)) + .setTextureState(new RenderStateShard.TextureStateShard(resourceLocation, false, false)) + .setTransparencyState(TRANSLUCENT_TRANSPARENCY) + .createCompositeState(true); + return create("mek_flame", DefaultVertexFormat.POSITION_TEX_COLOR, VertexFormat.Mode.QUADS, 256, true, false, state); + }); + public static final RenderType MEKASUIT = create("mekasuit", DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 131_072, true, false, + RenderType.CompositeState.builder() + .setShaderState(new ShaderStateShard(ShaderAccess::getMekasuitShader)) + .setTextureState(BLOCK_SHEET) + .setLightmapState(LIGHTMAP) + .setOverlayState(OVERLAY) + .createCompositeState(true) + ); + public LightningHandler(String pRenderType0, VertexFormat pVertexFormat1, VertexFormat.Mode pVertexFormat$Mode2, int pInt3, boolean pBoolean4, boolean pBoolean5, Runnable pRunnable6, Runnable pRunnable7) { super(pRenderType0, pVertexFormat1, pVertexFormat$Mode2, pInt3, pBoolean4, pBoolean5, pRunnable6, pRunnable7); } diff --git a/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderAccess.java b/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderAccess.java index 0675fe7169..9baa739972 100644 --- a/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderAccess.java +++ b/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderAccess.java @@ -3,6 +3,7 @@ import net.irisshaders.iris.Iris; import net.irisshaders.iris.pipeline.ShaderRenderingPipeline; import net.irisshaders.iris.pipeline.WorldRenderingPipeline; +import net.irisshaders.iris.shadows.ShadowRenderingState; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.ShaderInstance; @@ -20,4 +21,20 @@ public static ShaderInstance getParticleTranslucentShader() { return GameRenderer.getParticleShader(); } + + public static ShaderInstance getMekanismFlameShader() { + WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable(); + if (pipeline instanceof ShaderRenderingPipeline) { + return ((ShaderRenderingPipeline) pipeline).getShaderMap().getShader(ShadowRenderingState.areShadowsCurrentlyBeingRendered() ? ShaderKey.MEKANISM_FLAME_SHADOW : ShaderKey.MEKANISM_FLAME); + } + return GameRenderer.getPositionTexColorShader(); + } + + public static ShaderInstance getMekasuitShader() { + WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable(); + if (pipeline instanceof ShaderRenderingPipeline) { + return ((ShaderRenderingPipeline) pipeline).getShaderMap().getShader(ShadowRenderingState.areShadowsCurrentlyBeingRendered() ? ShaderKey.SHADOW_ENTITIES_CUTOUT : ShaderKey.ENTITIES_TRANSLUCENT); + } + return GameRenderer.getRendertypeEntityCutoutShader(); + } } diff --git a/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderKey.java b/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderKey.java index 8b05c9912f..2b5826096e 100644 --- a/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderKey.java +++ b/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderKey.java @@ -62,6 +62,7 @@ public enum ShaderKey { BEACON(ProgramId.BeaconBeam, AlphaTests.OFF, DefaultVertexFormat.BLOCK, FogMode.PER_FRAGMENT, LightingModel.FULLBRIGHT), GLINT(ProgramId.ArmorGlint, AlphaTests.NON_ZERO_ALPHA, DefaultVertexFormat.POSITION_TEX, FogMode.PER_VERTEX, LightingModel.LIGHTMAP), LINES(ProgramId.Line, AlphaTests.OFF, DefaultVertexFormat.POSITION_COLOR_NORMAL, FogMode.PER_VERTEX, LightingModel.LIGHTMAP), + MEKANISM_FLAME(ProgramId.SpiderEyes, AlphaTests.ONE_TENTH_ALPHA, DefaultVertexFormat.POSITION_TEX_COLOR, FogMode.PER_VERTEX, LightingModel.LIGHTMAP), // Note: These must be at the very end (NewWorldRenderingPipeline implementation details) SHADOW_TERRAIN_CUTOUT(ProgramId.Shadow, AlphaTests.ONE_TENTH_ALPHA, IrisVertexFormats.TERRAIN, FogMode.OFF, LightingModel.LIGHTMAP), @@ -78,7 +79,8 @@ public enum ShaderKey { SHADOW_PARTICLES(ProgramId.Shadow, AlphaTests.ONE_TENTH_ALPHA, DefaultVertexFormat.PARTICLE, FogMode.OFF, LightingModel.LIGHTMAP), SHADOW_TEXT(ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, IrisVertexFormats.GLYPH, FogMode.OFF, LightingModel.LIGHTMAP), SHADOW_TEXT_BG(ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, DefaultVertexFormat.POSITION_COLOR_LIGHTMAP, FogMode.OFF, LightingModel.LIGHTMAP), - SHADOW_TEXT_INTENSITY(ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, IrisVertexFormats.GLYPH, FogMode.OFF, LightingModel.LIGHTMAP); + SHADOW_TEXT_INTENSITY(ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, IrisVertexFormats.GLYPH, FogMode.OFF, LightingModel.LIGHTMAP), + MEKANISM_FLAME_SHADOW (ProgramId.ShadowEntities, AlphaTests.ONE_TENTH_ALPHA, DefaultVertexFormat.POSITION_TEX_COLOR, FogMode.OFF, LightingModel.LIGHTMAP); private final ProgramId program; private final AlphaTest alphaTest; diff --git a/src/main/java/net/irisshaders/iris/shaderpack/loading/ProgramId.java b/src/main/java/net/irisshaders/iris/shaderpack/loading/ProgramId.java index 9af15fb0ec..12bfaf815d 100644 --- a/src/main/java/net/irisshaders/iris/shaderpack/loading/ProgramId.java +++ b/src/main/java/net/irisshaders/iris/shaderpack/loading/ProgramId.java @@ -11,6 +11,7 @@ public enum ProgramId { Shadow(ProgramGroup.Shadow, ""), ShadowSolid(ProgramGroup.Shadow, "solid", Shadow), ShadowCutout(ProgramGroup.Shadow, "cutout", Shadow), + ShadowEntities(ProgramGroup.Shadow, "entities", Shadow, BlendModeOverride.OFF), Basic(ProgramGroup.Gbuffers, "basic"), Line(ProgramGroup.Gbuffers, "line", Basic), diff --git a/src/main/resources/mixins.oculus.json b/src/main/resources/mixins.oculus.json index 40192bea4c..b0e2ec6861 100644 --- a/src/main/resources/mixins.oculus.json +++ b/src/main/resources/mixins.oculus.json @@ -54,6 +54,8 @@ "entity_render_context.MixinBlockEntityRenderDispatcher", "entity_render_context.MixinCapeLayer", "entity_render_context.MixinElytraLayer", + "entity_render_context.MixinRenderFlame", + "entity_render_context.MixinRenderMekasuit", "entity_render_context.MixinEntityRenderDispatcher", "entity_render_context.MixinHorseArmorLayer", "entity_render_context.MixinHumanoidArmorLayer",