Skip to content

Commit

Permalink
More touches
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Aug 22, 2024
1 parent 1719c7e commit ed9d72c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
package net.irisshaders.iris.mixin;

import com.google.common.collect.ImmutableSet;
import com.mojang.blaze3d.shaders.Uniform;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.gl.GLDebug;
import net.irisshaders.iris.gl.blending.DepthColorStorage;
import net.irisshaders.iris.pipeline.ShaderRenderingPipeline;
import net.irisshaders.iris.pipeline.WorldRenderingPipeline;
import net.irisshaders.iris.pipeline.programs.ExtendedShader;
import net.irisshaders.iris.pipeline.programs.FallbackShader;
import net.irisshaders.iris.mixinterface.ShaderInstanceInterface;
import net.minecraft.client.renderer.CompiledShaderProgram;
import net.minecraft.server.packs.resources.ResourceProvider;
import org.lwjgl.opengl.KHRDebug;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(CompiledShaderProgram.class)
public abstract class MixinShaderInstance implements ShaderInstanceInterface {
public abstract class MixinCompiledShaderPrograms implements ShaderInstanceInterface {
@Unique
private static final ImmutableSet<String> ATTRIBUTE_LIST = ImmutableSet.of("Position", "Color", "Normal", "UV0", "UV1", "UV2");

Expand All @@ -42,20 +35,6 @@ private static boolean shouldOverrideShaders() {
}
}

@Shadow
@Final
private int programId;

// TODO IMS 24w34a
/*@Redirect(method = "<init>*", require = 1, at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/shaders/Uniform;glBindAttribLocation(IILjava/lang/CharSequence;)V"))
public void iris$redirectBindAttributeLocation(int i, int j, CharSequence charSequence) {
if (((Object) this) instanceof ExtendedShader && ATTRIBUTE_LIST.contains(charSequence)) {
Uniform.glBindAttribLocation(i, j, "iris_" + charSequence);
} else {
Uniform.glBindAttribLocation(i, j, charSequence);
}
}*/

@Inject(method = "apply", at = @At("HEAD"))
private void iris$lockDepthColorState(CallbackInfo ci) {
if (lastAppliedShader != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.irisshaders.iris.pipeline.IrisRenderingPipeline;
import net.irisshaders.iris.pipeline.WorldRenderingPhase;
import net.irisshaders.iris.pipeline.WorldRenderingPipeline;
import net.irisshaders.iris.pipeline.programs.ShaderAccess;
import net.irisshaders.iris.pipeline.programs.ShaderKey;
import net.irisshaders.iris.pipeline.programs.ShaderOverrides;
import net.irisshaders.iris.shadows.ShadowRenderingState;
Expand All @@ -16,7 +17,9 @@
import net.minecraft.client.renderer.CoreShaders;
import net.minecraft.client.renderer.ShaderManager;
import net.minecraft.client.renderer.ShaderProgram;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -27,7 +30,10 @@
import static net.irisshaders.iris.pipeline.programs.ShaderOverrides.isBlockEntities;

@Mixin(ShaderManager.class)
public class MixinRenderSystem_Overrides {
public abstract class MixinShaderManager_Overrides {
@Shadow
public abstract @Nullable CompiledShaderProgram getProgram(ShaderProgram shaderProgram);

private static final Function<IrisRenderingPipeline, ShaderKey> FAKE_FUNCTION = p -> null;

@Unique
Expand All @@ -41,7 +47,7 @@ public class MixinRenderSystem_Overrides {
coreShaderMap.put(CoreShaders.POSITION_COLOR, p -> ShaderOverrides.getSkyColorShader((IrisRenderingPipeline) p));
coreShaderMap.put(CoreShaders.PARTICLE, p -> ShaderOverrides.isPhase((IrisRenderingPipeline) p, WorldRenderingPhase.RAIN_SNOW) ? ShaderKey.WEATHER : ShaderKey.PARTICLES);
coreShaderMap.put(CoreShaders.RENDERTYPE_ENTITY_CUTOUT, p -> getCutout(p));
coreShaderMap.put(CoreShaders.RENDERTYPE_ENTITY_SOLID, p -> isBlockEntities((IrisRenderingPipeline) p) ? ShaderKey.MOVING_BLOCK : ShaderKey.ENTITIES_SOLID);
coreShaderMap.put(CoreShaders.RENDERTYPE_ENTITY_SOLID, p -> isBlockEntities((IrisRenderingPipeline) p) ? ShaderKey.BLOCK_ENTITY : ShaderKey.ENTITIES_SOLID);
coreShaderMap.put(CoreShaders.RENDERTYPE_ARMOR_CUTOUT_NO_CULL, p -> getCutout(p));
coreShaderMap.put(CoreShaders.RENDERTYPE_GLINT, p -> ShaderKey.GLINT);
coreShaderMap.put(CoreShaders.RENDERTYPE_ENTITY_GLINT, p -> ShaderKey.GLINT);
Expand All @@ -50,10 +56,10 @@ public class MixinRenderSystem_Overrides {
coreShaderMap.put(CoreShaders.RENDERTYPE_ENTITY_CUTOUT_NO_CULL, p -> getCutout(p));
coreShaderMap.put(CoreShaders.RENDERTYPE_ENTITY_CUTOUT_NO_CULL_Z_OFFSET, p -> getCutout(p));
coreShaderMap.put(CoreShaders.RENDERTYPE_ENTITY_SMOOTH_CUTOUT, p -> getCutout(p));
coreShaderMap.put(CoreShaders.RENDERTYPE_ENTITY_TRANSLUCENT, MixinRenderSystem_Overrides::getTranslucent);
coreShaderMap.put(CoreShaders.RENDERTYPE_ENTITY_TRANSLUCENT, MixinShaderManager_Overrides::getTranslucent);
coreShaderMap.put(CoreShaders.RENDERTYPE_ENTITY_TRANSLUCENT_EMISSIVE, p -> ShaderKey.ENTITIES_EYES_TRANS);
coreShaderMap.put(CoreShaders.RENDERTYPE_ENTITY_ALPHA, p -> ShaderKey.ENTITIES_ALPHA);
coreShaderMap.put(CoreShaders.RENDERTYPE_ITEM_ENTITY_TRANSLUCENT_CULL, MixinRenderSystem_Overrides::getTranslucent);
coreShaderMap.put(CoreShaders.RENDERTYPE_ITEM_ENTITY_TRANSLUCENT_CULL, MixinShaderManager_Overrides::getTranslucent);
coreShaderMap.put(CoreShaders.RENDERTYPE_SOLID, p -> ShaderOverrides.isBlockEntities((IrisRenderingPipeline) p) ? ShaderKey.MOVING_BLOCK : ShaderKey.TERRAIN_SOLID);
coreShaderMap.put(CoreShaders.RENDERTYPE_CUTOUT, p -> ShaderOverrides.isBlockEntities((IrisRenderingPipeline) p) ? ShaderKey.MOVING_BLOCK : ShaderKey.TERRAIN_CUTOUT);
coreShaderMap.put(CoreShaders.RENDERTYPE_CUTOUT_MIPPED, p -> ShaderOverrides.isBlockEntities((IrisRenderingPipeline) p) ? ShaderKey.MOVING_BLOCK : ShaderKey.TERRAIN_CUTOUT);
Expand All @@ -66,13 +72,13 @@ public class MixinRenderSystem_Overrides {
coreShaderMap.put(CoreShaders.RENDERTYPE_TEXT_INTENSITY, p -> ShaderOverrides.isBlockEntities((IrisRenderingPipeline) p) ? ShaderKey.TEXT_INTENSITY_BE : ShaderKey.TEXT_INTENSITY);
coreShaderMap.put(CoreShaders.RENDERTYPE_TEXT_INTENSITY_SEE_THROUGH, p -> ShaderOverrides.isBlockEntities((IrisRenderingPipeline) p) ? ShaderKey.TEXT_INTENSITY_BE : ShaderKey.TEXT_INTENSITY);
coreShaderMap.put(CoreShaders.RENDERTYPE_EYES, p -> ShaderKey.ENTITIES_EYES);
coreShaderMap.put(CoreShaders.RENDERTYPE_ENTITY_NO_OUTLINE, MixinRenderSystem_Overrides::getTranslucent);
coreShaderMap.put(CoreShaders.RENDERTYPE_BREEZE_WIND, MixinRenderSystem_Overrides::getTranslucent);
coreShaderMap.put(CoreShaders.RENDERTYPE_ENTITY_NO_OUTLINE, MixinShaderManager_Overrides::getTranslucent);
coreShaderMap.put(CoreShaders.RENDERTYPE_BREEZE_WIND, MixinShaderManager_Overrides::getTranslucent);
coreShaderMap.put(CoreShaders.RENDERTYPE_ENERGY_SWIRL, p -> ShaderKey.ENTITIES_CUTOUT);
coreShaderMap.put(CoreShaders.RENDERTYPE_BEACON_BEAM, p -> ShaderKey.BEACON);
coreShaderMap.put(CoreShaders.RENDERTYPE_LIGHTNING, p -> ShaderKey.LIGHTNING);
coreShaderMap.put(CoreShaders.RENDERTYPE_END_PORTAL, MixinRenderSystem_Overrides::getCutout);
coreShaderMap.put(CoreShaders.RENDERTYPE_END_GATEWAY, MixinRenderSystem_Overrides::getCutout);
coreShaderMap.put(CoreShaders.RENDERTYPE_END_PORTAL, MixinShaderManager_Overrides::getCutout);
coreShaderMap.put(CoreShaders.RENDERTYPE_END_GATEWAY, MixinShaderManager_Overrides::getCutout);
coreShaderMap.put(CoreShaders.RENDERTYPE_LEASH, p -> ShaderKey.LEASH);
coreShaderMap.put(CoreShaders.RENDERTYPE_WATER_MASK, p -> ShaderKey.ENTITIES_CUTOUT);
coreShaderMap.put(CoreShaders.RENDERTYPE_CLOUDS, p -> ShaderKey.CLOUDS);
Expand Down Expand Up @@ -160,13 +166,28 @@ private void redirectIrisProgram(ShaderProgram shaderProgram, CallbackInfoReturn
WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();

if (pipeline instanceof IrisRenderingPipeline irisPipeline && irisPipeline.shouldOverrideShaders()) {
CompiledShaderProgram program = override(irisPipeline, shaderProgram);
ShaderProgram newProgram = shaderProgram;

if (newProgram == ShaderAccess.MEKANISM_FLAME) {
CompiledShaderProgram result = irisPipeline.getShaderMap().getShader(ShadowRenderingState.areShadowsCurrentlyBeingRendered() ? ShaderKey.MEKANISM_FLAME_SHADOW : ShaderKey.MEKANISM_FLAME);

if (result != null) cir.setReturnValue(result);
} else if (shaderProgram == ShaderAccess.MEKASUIT) {
newProgram = CoreShaders.RENDERTYPE_ENTITY_CUTOUT;
}

CompiledShaderProgram program = override(irisPipeline, newProgram);

if (program != null) {
cir.setReturnValue(program);
} else if (Screen.hasAltDown()) {
System.out.println("We have a " + (ShadowRenderingState.areShadowsCurrentlyBeingRendered() ? "shadow " : "") + "program that can't be found; " + shaderProgram.configId());
new Exception().printStackTrace();
}
} else {
if (shaderProgram == ShaderAccess.MEKANISM_FLAME) {
cir.setReturnValue(getProgram(CoreShaders.POSITION_TEX_COLOR));
} else if (shaderProgram == ShaderAccess.MEKASUIT) {
cir.setReturnValue(getProgram(CoreShaders.RENDERTYPE_ENTITY_CUTOUT));
} else if (shaderProgram == ShaderAccess.IE_COMPAT) {
// TODO when IE updates
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,23 @@ public class LightningHandler extends RenderType {
.createCompositeState(false)
), new LightningRenderStateShard());

// TODO MEKANISM AGAIN 24w34a
public static final Function<ResourceLocation, RenderType> MEKANISM_FLAME = Util.memoize(resourceLocation -> {
RenderType.CompositeState state = RenderType.CompositeState.builder()
.setShaderState(new ShaderStateShard(ShaderAccess.MEKANISM_FLAME))
.setTextureState(new RenderStateShard.TextureStateShard(resourceLocation, TriState.DEFAULT, 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.MEKASUIT))
.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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import net.minecraft.client.renderer.CompiledShaderProgram;
import net.minecraft.client.renderer.CoreShaders;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.ShaderDefines;
import net.minecraft.client.renderer.ShaderProgram;
import net.minecraft.resources.ResourceLocation;

public class ShaderAccess {
public static VertexFormat IE_FORMAT = VertexFormat.builder()
Expand Down Expand Up @@ -47,24 +50,7 @@ public static CompiledShaderProgram getIEVBOShader() {
return null;
}

public static CompiledShaderProgram 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 Minecraft.getInstance().getShaderManager().getProgram(CoreShaders.POSITION_TEX_COLOR);
}

public static CompiledShaderProgram 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 Minecraft.getInstance().getShaderManager().getProgram(CoreShaders.RENDERTYPE_ENTITY_CUTOUT);
}
public static ShaderProgram MEKANISM_FLAME = new ShaderProgram(ResourceLocation.fromNamespaceAndPath("iris", "mekanism_flame"), DefaultVertexFormat.POSITION_TEX_COLOR, ShaderDefines.EMPTY);
public static ShaderProgram MEKASUIT = new ShaderProgram(ResourceLocation.fromNamespaceAndPath("iris", "mekasuit"), DefaultVertexFormat.NEW_ENTITY, ShaderDefines.EMPTY);
public static ShaderProgram IE_COMPAT = new ShaderProgram(ResourceLocation.fromNamespaceAndPath("iris", "ie_vbo"), IE_FORMAT, ShaderDefines.EMPTY);
}
4 changes: 2 additions & 2 deletions common/src/main/resources/mixins.iris.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
"MixinProgram",
"MixinQuickPlayDev",
"MixinRenderSystem",
"MixinRenderSystem_Overrides",
"MixinShaderManager_Overrides",
"MixinRenderTarget",
"MixinScreenEffectRenderer",
"MixinShaderInstance",
"MixinCompiledShaderPrograms",
"MixinSystemReport",
"MixinTheEndPortalRenderer",
"MixinTitleScreen",
Expand Down

0 comments on commit ed9d72c

Please sign in to comment.