Skip to content

Commit

Permalink
Goo magic
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Jan 23, 2025
1 parent 6541195 commit a46a439
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public String toExpression(String alphaAccessor, String alphaThreshold, String i

if (function == AlphaTestFunction.ALWAYS) {
return "// alpha test disabled\n";
} else if (this == AlphaTests.VERTEX_ALPHA) {
} else if (this.reference == Float.MAX_VALUE) {
return indentation + "if (!(" + alphaAccessor + " > iris_vertexColorAlpha)) {\n" +
indentation + " discard;\n" +
indentation + "}\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ public class AlphaTests {
public static final AlphaTest NON_ZERO_ALPHA = new AlphaTest(AlphaTestFunction.GREATER, 0.0001F);
public static final AlphaTest ONE_TENTH_ALPHA = new AlphaTest(AlphaTestFunction.GREATER, 0.1F);

public static final AlphaTest VERTEX_ALPHA = new AlphaTest(AlphaTestFunction.NEVER, 0);
public static final AlphaTest VERTEX_ALPHA = new AlphaTest(AlphaTestFunction.NEVER, Float.MAX_VALUE);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public static ImmutableList<StringPair> createStandardEnvironmentDefines() {
define(standardDefines, "IRIS_HAS_CONNECTED_TEXTURES");
}

if (IrisPlatformHelpers.getInstance().isModLoaded("monocle")) {
define(standardDefines, "IS_MONOCLE");
}

define(standardDefines, "DH_BLOCK_UNKNOWN", String.valueOf(0));
define(standardDefines, "DH_BLOCK_LEAVES", String.valueOf(1));
define(standardDefines, "DH_BLOCK_STONE", String.valueOf(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public BufferSourceWrapper(MultiBufferSource bufferSource, Function<RenderType,
this.typeChanger = typeChanger;
}

public MultiBufferSource getOriginal() {
return bufferSource;
}

@Override
public void startGroup() {
if (bufferSource instanceof Groupable groupable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.irisshaders.iris.shadows.ShadowRenderer;
import net.irisshaders.iris.uniforms.CapturedRenderingState;
import net.irisshaders.iris.uniforms.SystemTimeUniforms;
import net.irisshaders.iris.vertices.ImmediateState;
import net.minecraft.Util;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -456,7 +457,7 @@ private static boolean shouldOverrideShaders() {
private static void override(ShaderKey key, CallbackInfoReturnable<ShaderInstance> cir) {
WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();

if (pipeline instanceof ShaderRenderingPipeline) {
if (pipeline instanceof ShaderRenderingPipeline && !ImmediateState.bypass) {
ShaderInstance override = ((ShaderRenderingPipeline) pipeline).getShaderMap().getShader(key);

if (override != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import org.joml.Vector3d;
import org.joml.Vector4f;
import org.lwjgl.opengl.ARBClearTexture;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL15C;
import org.lwjgl.opengl.GL20C;
import org.lwjgl.opengl.GL21C;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static void transform(

if (parameters.inputs.hasColor() && parameters.type == PatchShaderType.VERTEX) {
// TODO: Handle the fragment / geometry shader here
if (parameters.alpha == AlphaTests.VERTEX_ALPHA) {
if (parameters.alpha.reference() == Float.MAX_VALUE) {
root.replaceReferenceExpressions(t, "gl_Color",
"vec4((iris_Color * iris_ColorModulator).rgb, iris_ColorModulator.a)");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.platform.IrisPlatformHelpers;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -43,7 +44,7 @@ private static void addTag(TagEntry tagEntry, Object2IntMap<BlockState> idMap, i
List<TagKey<Block>> compatibleTags = BuiltInRegistries.BLOCK.getTagNames().filter(t -> t.location().getNamespace().equalsIgnoreCase(tagEntry.id().getNamespace()) &&
t.location().getPath().equalsIgnoreCase(tagEntry.id().getName())).toList();

if (compatibleTags.isEmpty()) {
if (compatibleTags.isEmpty() && IrisPlatformHelpers.getInstance().isDevelopmentEnvironment()) {
Iris.logger.warn("Failed to find the tag " + tagEntry.id());
} else if (compatibleTags.size() > 1) {
Iris.logger.fatal("You've broke the system; congrats. More than one tag matched " + tagEntry.id());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public class ImmediateState {
public static boolean isRenderingLevel = false;
public static boolean usingTessellation = false;
public static boolean renderWithExtendedVertexFormat = true;
public static boolean bypass;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.irisshaders.iris.mixin.forge;

import net.irisshaders.iris.pipeline.programs.ShaderAccess;
import net.irisshaders.iris.platform.Bypass;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.RenderStateShard;
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 = "com/direwolf20/justdirethings/client/renderers/OurRenderTypes")
public class MixinGooBlock {
@Redirect(method = "<clinit>", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/RenderStateShard;RENDERTYPE_TRANSLUCENT_SHADER:Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;"))
private static RenderStateShard.ShaderStateShard redirectAlpha() {
return new Bypass(GameRenderer::getRendertypeTranslucentShader);
}

@Redirect(method = "<clinit>", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/RenderStateShard;RENDERTYPE_ENTITY_ALPHA_SHADER:Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;"))
private static RenderStateShard.ShaderStateShard redirectAlpha2() {
return new Bypass(GameRenderer::getRendertypeEntityAlphaShader);
}
}
18 changes: 18 additions & 0 deletions neoforge/src/main/java/net/irisshaders/iris/platform/Bypass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.irisshaders.iris.platform;

import net.irisshaders.iris.vertices.ImmediateState;
import net.minecraft.client.renderer.RenderStateShard;
import net.minecraft.client.renderer.ShaderInstance;

import java.util.function.Supplier;

public class Bypass extends RenderStateShard.ShaderStateShard {
public Bypass(Supplier<ShaderInstance> original) {
super(() -> {
ImmediateState.bypass = true;
ShaderInstance i = original.get();
ImmediateState.bypass = false;
return i;
});
}
}
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 @@ -6,6 +6,7 @@
"client": [
"MixinHumanoidArmorLayer",
"MixinGameClientEvents",
"MixinGooBlock",
"MixinItemBlockRenderTypes",
"MixinShaderInstance",
"MixinRenderFlame",
Expand Down

0 comments on commit a46a439

Please sign in to comment.