Skip to content

Commit

Permalink
Mekasuit render fix backport. (#701)
Browse files Browse the repository at this point in the history
* Mekasuit render fix backport. fixes #170

* Fixed tabulations and spaces.

* Fixed inconsistent tabulation length between GitHub and IDEs. Replaced tabs with spaces to ensure consistent formatting across environments.

* Revert "Fixed inconsistent tabulation length between GitHub and IDEs. Replaced tabs with spaces to ensure consistent formatting across environments."

This reverts commit 3a0a300.

* Revert "Fixed tabulations and spaces."

This reverts commit ded724e.

* Revert formatting for ShaderKey.
  • Loading branch information
KostromDan authored Oct 18, 2024
1 parent d2bc9aa commit 0573ebc
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/main/java/net/coderbot/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public Iris() {
}
}

public static boolean isPackInUseQuick() {
return getPipelineManager().getPipelineNullable() instanceof NewWorldRenderingPipeline;
}

/**
* Called very early on in Minecraft initialization. At this point we *cannot* safely access OpenGL, but we can do
* some very basic setup, config loading, and environment checks.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.coderbot.iris.mixin.entity_render_context;

import net.coderbot.iris.Iris;
import net.coderbot.iris.pipeline.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<ResourceLocation, RenderType> doNotSwitchShaders() {
if (Iris.isPackInUseQuick()) {
return LightningHandler.MEKANISM_FLAME;
} else {
return (Function<ResourceLocation, RenderType>) MEKANISM_FLAME;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.coderbot.iris.mixin.entity_render_context;

import net.coderbot.iris.Iris;
import net.coderbot.iris.pipeline.LightningHandler;
import net.coderbot.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;
}
}
}
25 changes: 24 additions & 1 deletion src/main/java/net/coderbot/iris/pipeline/LightningHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
import com.mojang.blaze3d.vertex.VertexFormat;
import net.coderbot.iris.layer.InnerWrappedRenderType;
import net.coderbot.iris.layer.LightningRenderStateShard;
import net.coderbot.iris.layer.OuterWrappedRenderType;
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(
Expand All @@ -23,6 +28,24 @@ public class LightningHandler extends RenderType {
.createCompositeState(false)
), new LightningRenderStateShard());

public static final Function<ResourceLocation, RenderType> 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);
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/net/coderbot/iris/pipeline/ShaderAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.coderbot.iris.Iris;
import net.coderbot.iris.pipeline.newshader.CoreWorldRenderingPipeline;
import net.coderbot.iris.pipeline.newshader.ShaderKey;
import net.coderbot.iris.shadows.ShadowRenderingState;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.ShaderInstance;

Expand All @@ -20,4 +21,24 @@ public static ShaderInstance getParticleTranslucentShader() {

return GameRenderer.getParticleShader();
}
public static ShaderInstance getMekanismFlameShader() {
WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();

if (pipeline instanceof CoreWorldRenderingPipeline) {

return ((CoreWorldRenderingPipeline) 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 CoreWorldRenderingPipeline) {
return ((CoreWorldRenderingPipeline) pipeline).getShaderMap().getShader(ShadowRenderingState.areShadowsCurrentlyBeingRendered() ? ShaderKey.SHADOW_ENTITIES_CUTOUT : ShaderKey.ENTITIES_TRANSLUCENT);
}

return GameRenderer.getRendertypeEntityCutoutShader();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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 ),
Expand All @@ -73,7 +74,9 @@ public enum ShaderKey {
SHADOW_LIGHTNING (ProgramId.Shadow, AlphaTests.OFF, DefaultVertexFormat.POSITION_COLOR, FogMode.OFF, LightingModel.FULLBRIGHT),
SHADOW_PARTICLES (ProgramId.Shadow, AlphaTests.ONE_TENTH_ALPHA, DefaultVertexFormat.PARTICLE, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_TEXT (ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, IrisVertexFormats.ENTITY , FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_TEXT_INTENSITY (ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, IrisVertexFormats.ENTITY , FogMode.OFF, LightingModel.LIGHTMAP );
SHADOW_TEXT_INTENSITY (ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, IrisVertexFormats.ENTITY , 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/mixins.oculus.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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",
Expand Down

0 comments on commit 0573ebc

Please sign in to comment.