diff --git a/common/src/main/java/net/irisshaders/iris/mixin/MixinChunkBorderRenderer.java b/common/src/main/java/net/irisshaders/iris/mixin/MixinChunkBorderRenderer.java index 5c10141514..7e5a7eb91f 100644 --- a/common/src/main/java/net/irisshaders/iris/mixin/MixinChunkBorderRenderer.java +++ b/common/src/main/java/net/irisshaders/iris/mixin/MixinChunkBorderRenderer.java @@ -42,36 +42,4 @@ public VertexConsumer setNormal(float normalX, float normalY, float normalZ) { return this; } }; - - @Redirect( - method = "render", - at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/VertexConsumer;addVertex(Lorg/joml/Matrix4f;FFF)Lcom/mojang/blaze3d/vertex/VertexConsumer;"), - slice = @Slice( - from = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack$Pose;pose()Lorg/joml/Matrix4f;"), - to = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/debug/ChunkBorderRenderer;CELL_BORDER:I", ordinal = 0) - ) - ) - private VertexConsumer isCameraChunk(VertexConsumer instance, Matrix4f pose, float x, float y, float z, @Local(ordinal = 0) int k, @Local(ordinal = 1) int l) { - if (!((k == 0 || k == 16) && (l == 0 || l == 16))) { - return instance.addVertex(pose, x,y ,z); - } else { - return fakeConsumer; - } - } - - @Redirect( - method = "render", - at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/VertexConsumer;addVertex(Lorg/joml/Matrix4f;FFF)Lcom/mojang/blaze3d/vertex/VertexConsumer;"), - slice = @Slice( - from = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientLevel;getMinBuildHeight()I", ordinal = 1), - to = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource;getBuffer(Lnet/minecraft/client/renderer/RenderType;)Lcom/mojang/blaze3d/vertex/VertexConsumer;", ordinal = 1) - ) - ) - private VertexConsumer isSubChunkBorder(VertexConsumer instance, Matrix4f pose, float x, float y, float z, @Local(ordinal = 0) int k) { - if (k % 16 != 0) { - return instance.addVertex(pose, x,y ,z); - } else { - return fakeConsumer; - } - } } diff --git a/common/src/main/java/net/irisshaders/iris/mixin/MixinLevelRenderer.java b/common/src/main/java/net/irisshaders/iris/mixin/MixinLevelRenderer.java index 8959b0d529..4fc6b70be6 100644 --- a/common/src/main/java/net/irisshaders/iris/mixin/MixinLevelRenderer.java +++ b/common/src/main/java/net/irisshaders/iris/mixin/MixinLevelRenderer.java @@ -79,11 +79,6 @@ public class MixinLevelRenderer { @Shadow private Frustum cullingFrustum; - @Shadow - private @Nullable ClientLevel level; - @Shadow - @Final - private LevelTargetBundle targets; private boolean warned; // Begin shader rendering after buffers have been cleared. @@ -106,7 +101,8 @@ public class MixinLevelRenderer { if (pipeline.shouldDisableFrustumCulling()) { this.cullingFrustum = new NonCullingFrustum(); } - + pipeline.beginLevelRendering(); + pipeline.setPhase(WorldRenderingPhase.NONE); Minecraft.getInstance().smartCull = !pipeline.shouldDisableOcclusionCulling(); if (Iris.shouldActivateWireframe() && this.minecraft.isLocalServer()) { @@ -120,8 +116,7 @@ public class MixinLevelRenderer { // all pixels. @Inject(method = "method_62218", at = @At(value = "TAIL")) private static void iris$beginLevelRender(Vector4f vector4f, CallbackInfo ci) { - pipeline.beginLevelRendering(); - pipeline.setPhase(WorldRenderingPhase.NONE); + } @@ -149,14 +144,10 @@ public class MixinLevelRenderer { // avoid breaking other mods such as Light Overlay: https://github.com/IrisShaders/Iris/issues/1356 // Do this before sky rendering so it's ready before the sky render starts. - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/framegraph/FramePass;executes(Ljava/lang/Runnable;)V", ordinal = 0, shift = At.Shift.AFTER)) - private void iris$renderTerrainShadows(GraphicsResourceAllocator graphicsResourceAllocator, DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci, @Local FrameGraphBuilder frameGraphBuilder) { - FramePass framePass = frameGraphBuilder.addPass("shadows"); - this.targets.main = framePass.readsAndWrites(this.targets.main); - - framePass.executes(() -> { - pipeline.renderShadows((LevelRendererAccessor) this, camera); - }); + @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;collectVisibleEntities(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/culling/Frustum;Ljava/util/List;)Z", shift = At.Shift.AFTER)) + private void iris$renderTerrainShadows(GraphicsResourceAllocator graphicsResourceAllocator, DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) { + pipeline.renderShadows((LevelRendererAccessor) this, camera); + } // TODO IMS 1.21.2 diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java b/common/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java index 3cf5454e57..099ba46f81 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java @@ -95,8 +95,8 @@ public ExtendedShader(int programId, ResourceProvider resourceFactory, String st uniformList.add(new ShaderProgramConfig.Uniform("iris_FogStart", "float", 1, List.of(0.0f))); uniformList.add(new ShaderProgramConfig.Uniform("iris_FogEnd", "float", 1, List.of(1.0f))); uniformList.add(new ShaderProgramConfig.Uniform("iris_GlintAlpha", "float", 1, List.of(0.0f))); - uniformList.add(new ShaderProgramConfig.Uniform("iris_ModelViewMatInverse", "float", 1, List.of(0.0f))); - uniformList.add(new ShaderProgramConfig.Uniform("iris_ProjMatInverse", "float", 1, List.of(0.0f))); + uniformList.add(new ShaderProgramConfig.Uniform("iris_ModelViewMatInverse", "matrix4x4", 16, List.of(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f))); + uniformList.add(new ShaderProgramConfig.Uniform("iris_ProjMatInverse", "matrix4x4", 16, List.of(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f))); samplerList.add(new ShaderProgramConfig.Sampler("Sampler0")); setupUniforms(uniformList, samplerList); diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/programs/FallbackShader.java b/common/src/main/java/net/irisshaders/iris/pipeline/programs/FallbackShader.java index 17e074c2dc..01fe56180a 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/programs/FallbackShader.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/programs/FallbackShader.java @@ -13,6 +13,7 @@ import net.irisshaders.iris.uniforms.CapturedRenderingState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.CompiledShaderProgram; +import net.minecraft.client.renderer.ShaderProgramConfig; import net.minecraft.server.packs.resources.ResourceProvider; import org.jetbrains.annotations.Nullable; @@ -34,11 +35,13 @@ public class FallbackShader extends CompiledShaderProgram { private final int overlay; private final int lightmap; - public FallbackShader(int programId, ResourceProvider resourceFactory, String string, VertexFormat vertexFormat, + public FallbackShader(int programId, ShaderProgramConfig shaderProgramConfig, ResourceProvider resourceFactory, String string, VertexFormat vertexFormat, GlFramebuffer writingToBeforeTranslucent, GlFramebuffer writingToAfterTranslucent, BlendModeOverride blendModeOverride, float alphaValue, IrisRenderingPipeline parent) throws IOException { super(programId); + setupUniforms(shaderProgramConfig.uniforms(), shaderProgramConfig.samplers()); + this.parent = parent; this.blendModeOverride = blendModeOverride; this.writingToBeforeTranslucent = writingToBeforeTranslucent; diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderCreator.java b/common/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderCreator.java index 368d01599a..354754e73f 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderCreator.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/programs/ShaderCreator.java @@ -2,10 +2,14 @@ import com.google.common.collect.ImmutableSet; import com.google.common.primitives.Ints; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.google.gson.JsonSyntaxException; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.shaders.CompiledShader; import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.VertexFormat; +import com.mojang.serialization.JsonOps; import net.irisshaders.iris.Iris; import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.shader.ShaderCompileException; @@ -33,6 +37,7 @@ import net.irisshaders.iris.platform.IrisPlatformHelpers; import net.minecraft.client.renderer.CompiledShaderProgram; import net.minecraft.client.renderer.ShaderManager; +import net.minecraft.client.renderer.ShaderProgramConfig; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.PackLocationInfo; @@ -282,10 +287,13 @@ public static FallbackShader createFallback(String name, GlFramebuffer writingTo .addJson(shaderJsonString) .print(); + JsonElement jsonElement = JsonParser.parseString(shaderJsonString); + ShaderProgramConfig shaderProgramConfig = ShaderProgramConfig.CODEC.parse(JsonOps.INSTANCE, jsonElement).getOrThrow(JsonSyntaxException::new); + ResourceProvider shaderResourceFactory = new IrisProgramResourceFactory(shaderJsonString, vertex, null, null, null, fragment); // TODO 24w34a FALLBACK - return new FallbackShader(0, shaderResourceFactory, name, vertexFormat, writingToBeforeTranslucent, + return new FallbackShader(link(name, vertex, null, null, null, fragment, vertexFormat), shaderProgramConfig, shaderResourceFactory, name, vertexFormat, writingToBeforeTranslucent, writingToAfterTranslucent, blendModeOverride, alpha.reference(), parent); }