Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mekasuit render fix backport. #701

Open
wants to merge 1 commit into
base: 1.19.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
31 changes: 17 additions & 14 deletions src/main/java/net/coderbot/iris/pipeline/newshader/ShaderKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,25 @@ 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 ),
SHADOW_ENTITIES_CUTOUT (ProgramId.Shadow, AlphaTests.ONE_TENTH_ALPHA, IrisVertexFormats.ENTITY, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_BEACON_BEAM (ProgramId.Shadow, AlphaTests.OFF, DefaultVertexFormat.BLOCK, FogMode.OFF, LightingModel.FULLBRIGHT),
SHADOW_BASIC (ProgramId.Shadow, AlphaTests.OFF, DefaultVertexFormat.POSITION, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_BASIC_COLOR (ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, DefaultVertexFormat.POSITION_COLOR, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_TEX (ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, DefaultVertexFormat.POSITION_TEX, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_TEX_COLOR (ProgramId.Shadow, AlphaTests.ONE_TENTH_ALPHA, DefaultVertexFormat.POSITION_TEX_COLOR, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_CLOUDS (ProgramId.Shadow, AlphaTests.ONE_TENTH_ALPHA, DefaultVertexFormat.POSITION_TEX_COLOR_NORMAL, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_LINES (ProgramId.Shadow, AlphaTests.OFF, DefaultVertexFormat.POSITION_COLOR_NORMAL, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_LEASH (ProgramId.Shadow, AlphaTests.OFF, DefaultVertexFormat.POSITION_COLOR_LIGHTMAP, FogMode.OFF, LightingModel.LIGHTMAP ),
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_TERRAIN_CUTOUT (ProgramId.Shadow, AlphaTests.ONE_TENTH_ALPHA, IrisVertexFormats.TERRAIN, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_ENTITIES_CUTOUT (ProgramId.Shadow, AlphaTests.ONE_TENTH_ALPHA, IrisVertexFormats.ENTITY, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_BEACON_BEAM (ProgramId.Shadow, AlphaTests.OFF, DefaultVertexFormat.BLOCK, FogMode.OFF, LightingModel.FULLBRIGHT),
SHADOW_BASIC (ProgramId.Shadow, AlphaTests.OFF, DefaultVertexFormat.POSITION, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_BASIC_COLOR (ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, DefaultVertexFormat.POSITION_COLOR, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_TEX (ProgramId.Shadow, AlphaTests.NON_ZERO_ALPHA, DefaultVertexFormat.POSITION_TEX, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_TEX_COLOR (ProgramId.Shadow, AlphaTests.ONE_TENTH_ALPHA, DefaultVertexFormat.POSITION_TEX_COLOR, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_CLOUDS (ProgramId.Shadow, AlphaTests.ONE_TENTH_ALPHA, DefaultVertexFormat.POSITION_TEX_COLOR_NORMAL, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_LINES (ProgramId.Shadow, AlphaTests.OFF, DefaultVertexFormat.POSITION_COLOR_NORMAL, FogMode.OFF, LightingModel.LIGHTMAP ),
SHADOW_LEASH (ProgramId.Shadow, AlphaTests.OFF, DefaultVertexFormat.POSITION_COLOR_LIGHTMAP, FogMode.OFF, LightingModel.LIGHTMAP ),
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 ),
MEKANISM_FLAME_SHADOW (ProgramId.ShadowEntities, AlphaTests.ONE_TENTH_ALPHA, DefaultVertexFormat.POSITION_TEX_COLOR, FogMode.OFF, LightingModel.LIGHTMAP );

Comment on lines -63 to +79
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I accidentally highlighted an extra line (the last one with MEKANISM_FLAME_SHADOW), it doesn't need to be rolled back


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