Skip to content

Commit

Permalink
Support SPS
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Nov 11, 2024
1 parent 220a694 commit d68f869
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public class LightningHandler extends RenderType {
.createCompositeState(true)
);

public static final Function<ResourceLocation, RenderType> SPS = Util.memoize(r -> new InnerWrappedRenderType("iris_sps", create("sps", DefaultVertexFormat.POSITION_TEX_COLOR, VertexFormat.Mode.QUADS, 1_536, true, false,
RenderType.CompositeState.builder()
.setShaderState(new ShaderStateShard(ShaderAccess::getSPSShader))
.setTextureState(new RenderStateShard.TextureStateShard(r, false, false))
.setTransparencyState(RenderStateShard.LIGHTNING_TRANSPARENCY)
.createCompositeState(true)
), new LightningRenderStateShard()));

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 @@ -63,4 +63,14 @@ public static ShaderInstance getMekasuitShader() {

return GameRenderer.getRendertypeEntityCutoutShader();
}

public static ShaderInstance getSPSShader() {
WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();

if (pipeline instanceof ShaderRenderingPipeline) {
return ((ShaderRenderingPipeline) pipeline).getShaderMap().getShader(ShadowRenderingState.areShadowsCurrentlyBeingRendered() ? ShaderKey.SHADOW_LIGHTNING : ShaderKey.SPS);
}

return GameRenderer.getRendertypeEntityCutoutShader();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum ShaderKey {
BASIC_COLOR(ProgramId.Basic, AlphaTests.NON_ZERO_ALPHA, DefaultVertexFormat.POSITION_COLOR, FogMode.OFF, LightingModel.LIGHTMAP),
TEXTURED(ProgramId.Textured, AlphaTests.NON_ZERO_ALPHA, DefaultVertexFormat.POSITION_TEX, FogMode.OFF, LightingModel.LIGHTMAP),
TEXTURED_COLOR(ProgramId.Textured, AlphaTests.ONE_TENTH_ALPHA, DefaultVertexFormat.POSITION_TEX_COLOR, FogMode.OFF, LightingModel.LIGHTMAP),
SPS(ProgramId.Lightning, AlphaTests.ONE_TENTH_ALPHA, DefaultVertexFormat.POSITION_TEX_COLOR, FogMode.PER_FRAGMENT, LightingModel.FULLBRIGHT),
SKY_BASIC(ProgramId.SkyBasic, AlphaTests.OFF, DefaultVertexFormat.POSITION, FogMode.PER_VERTEX, LightingModel.LIGHTMAP),
SKY_BASIC_COLOR(ProgramId.SkyBasic, AlphaTests.NON_ZERO_ALPHA, DefaultVertexFormat.POSITION_COLOR, FogMode.OFF, LightingModel.LIGHTMAP),
SKY_TEXTURED(ProgramId.SkyTextured, AlphaTests.OFF, DefaultVertexFormat.POSITION_TEX, FogMode.OFF, LightingModel.LIGHTMAP),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.irisshaders.iris.mixin.forge;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.pathways.LightningHandler;
import net.irisshaders.iris.vertices.ImmediateState;
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 java.util.function.Function;

@Pseudo
@Mixin(targets = "mekanism.client.render.lib.effect.BillboardingEffectRenderer", remap = false)
public class MixinRenderSPS {
@WrapOperation(method = "render(Lnet/minecraft/resources/ResourceLocation;Ljava/lang/String;Ljava/util/function/Supplier;)V", at = @At(
value = "FIELD",
target = "Lmekanism/client/render/MekanismRenderType;SPS:Ljava/util/function/Function;"))
private static Function<ResourceLocation, RenderType> doNotSwitchShaders(Operation<Function<ResourceLocation, RenderType>> original) {
if (Iris.isPackInUseQuick() && ImmediateState.isRenderingLevel) {
return LightningHandler.SPS;
} else {
return original.call();
}
}
}
1 change: 1 addition & 0 deletions neoforge/src/main/resources/mixins.iris.forge.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"MixinShaderInstance",
"MixinRenderFlame",
"MixinRenderMekasuit",
"MixinRenderSPS",
"MixinShadowRenderer",
"MixinVBOIE"
],
Expand Down

0 comments on commit d68f869

Please sign in to comment.