From 3297370704d2505f72451b6048c25d63d2df9b2a Mon Sep 17 00:00:00 2001 From: IMS212 Date: Mon, 4 Nov 2024 14:21:31 -0800 Subject: [PATCH 1/2] Fix shadows not working correctly in many situations --- build.gradle.kts | 2 +- .../irisshaders/iris/compat/dh/DHCompatInternal.java | 4 ++-- .../net/irisshaders/iris/shadows/ShadowRenderer.java | 3 ++- .../net/irisshaders/iris/uniforms/MatrixUniforms.java | 10 +++++++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8d003e3f9b..e2b7849303 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ val FABRIC_API_VERSION by extra { "0.103.0+1.21.1" } val PARCHMENT_VERSION by extra { null } // https://semver.org/ -val MOD_VERSION by extra { "1.8.0-beta.5" } +val MOD_VERSION by extra { "1.8.0-beta.7" } allprojects { apply(plugin = "java") diff --git a/common/src/main/java/net/irisshaders/iris/compat/dh/DHCompatInternal.java b/common/src/main/java/net/irisshaders/iris/compat/dh/DHCompatInternal.java index 66418d0099..6ba7fbf291 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/dh/DHCompatInternal.java +++ b/common/src/main/java/net/irisshaders/iris/compat/dh/DHCompatInternal.java @@ -99,9 +99,9 @@ public DHCompatInternal(IrisRenderingPipeline pipeline, boolean dhShadowEnabled) } public static int getDhBlockRenderDistance() { - if (DhApi.Delayed.configs == null) { + if (DhApi.Delayed.configs == null || !dhEnabled) { // Called before DH has finished setup - return 0; + return Minecraft.getInstance().options.getEffectiveRenderDistance(); } return DhApi.Delayed.configs.graphics().chunkRenderDistance().getValue() * 16; diff --git a/common/src/main/java/net/irisshaders/iris/shadows/ShadowRenderer.java b/common/src/main/java/net/irisshaders/iris/shadows/ShadowRenderer.java index c496386ab0..1d9f5e608d 100644 --- a/common/src/main/java/net/irisshaders/iris/shadows/ShadowRenderer.java +++ b/common/src/main/java/net/irisshaders/iris/shadows/ShadowRenderer.java @@ -41,6 +41,7 @@ import net.minecraft.client.renderer.culling.Frustum; import net.minecraft.client.renderer.entity.EntityRenderDispatcher; import net.minecraft.core.BlockPos; +import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.block.entity.BlockEntity; import org.joml.Matrix4f; @@ -393,7 +394,7 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame // If FOV is not null, the pack wants a perspective based projection matrix. (This is to support legacy packs) shadowProjection = ShadowMatrices.createPerspectiveMatrix(this.fov); } else { - shadowProjection = ShadowMatrices.createOrthoMatrix(halfPlaneLength, nearPlane < 0 ? -DHCompat.getRenderDistance() * 16 : nearPlane, farPlane < 0 ? DHCompat.getRenderDistance() * 16 : farPlane); + shadowProjection = ShadowMatrices.createOrthoMatrix(halfPlaneLength, Mth.equal(nearPlane, -1.0f) ? -DHCompat.getRenderDistance() * 16 : nearPlane, Mth.equal(farPlane, -1.0f) ? DHCompat.getRenderDistance() * 16 : farPlane); } IrisRenderSystem.setShadowProjection(shadowProjection); diff --git a/common/src/main/java/net/irisshaders/iris/uniforms/MatrixUniforms.java b/common/src/main/java/net/irisshaders/iris/uniforms/MatrixUniforms.java index 8f33aae815..a9115250f5 100644 --- a/common/src/main/java/net/irisshaders/iris/uniforms/MatrixUniforms.java +++ b/common/src/main/java/net/irisshaders/iris/uniforms/MatrixUniforms.java @@ -5,6 +5,7 @@ import net.irisshaders.iris.shaderpack.properties.PackDirectives; import net.irisshaders.iris.shadows.ShadowMatrices; import net.irisshaders.iris.shadows.ShadowRenderer; +import net.minecraft.util.Mth; import org.joml.Matrix4f; import org.joml.Matrix4fc; @@ -21,10 +22,13 @@ public static void addMatrixUniforms(UniformHolder uniforms, PackDirectives dire addMatrix(uniforms, "Projection", CapturedRenderingState.INSTANCE::getGbufferProjection); addDHMatrix(uniforms, "Projection", DHCompat::getProjection); addShadowMatrix(uniforms, "ModelView", () -> - new Matrix4f(ShadowRenderer.createShadowModelView(directives.getSunPathRotation(), directives.getShadowDirectives().getIntervalSize(), directives.getShadowDirectives().getNearPlane(), directives.getShadowDirectives().getFarPlane()).last().pose())); + new Matrix4f(ShadowRenderer.createShadowModelView(directives.getSunPathRotation(), directives.getShadowDirectives().getIntervalSize(), + Mth.equal(directives.getShadowDirectives().getNearPlane(), -1.0f) ? -DHCompat.getRenderDistance() * 16 : directives.getShadowDirectives().getNearPlane(), + Mth.equal(directives.getShadowDirectives().getFarPlane(), -1.0f) ? DHCompat.getRenderDistance() * 16 : directives.getShadowDirectives().getFarPlane() + ).last().pose())); addShadowMatrix(uniforms, "Projection", () -> ShadowMatrices.createOrthoMatrix(directives.getShadowDirectives().getDistance(), - directives.getShadowDirectives().getNearPlane() < 0 ? -DHCompat.getRenderDistance() * 16 : directives.getShadowDirectives().getNearPlane(), - directives.getShadowDirectives().getFarPlane() < 0 ? DHCompat.getRenderDistance() * 16 : directives.getShadowDirectives().getFarPlane())); + Mth.equal(directives.getShadowDirectives().getNearPlane(), -1.0f) ? -DHCompat.getRenderDistance() * 16 : directives.getShadowDirectives().getNearPlane(), + Mth.equal(directives.getShadowDirectives().getFarPlane(), -1.0f) ? DHCompat.getRenderDistance() * 16 : directives.getShadowDirectives().getFarPlane())); } private static void addMatrix(UniformHolder uniforms, String name, Supplier supplier) { From 9e87a8e357b711d3f2372173754fb880cc5abe7e Mon Sep 17 00:00:00 2001 From: IMS212 Date: Tue, 5 Nov 2024 07:23:33 -0800 Subject: [PATCH 2/2] Fix incorrect projection size --- .../main/java/net/irisshaders/iris/shadows/ShadowMatrices.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/net/irisshaders/iris/shadows/ShadowMatrices.java b/common/src/main/java/net/irisshaders/iris/shadows/ShadowMatrices.java index b51a075fe4..7c5cde9471 100644 --- a/common/src/main/java/net/irisshaders/iris/shadows/ShadowMatrices.java +++ b/common/src/main/java/net/irisshaders/iris/shadows/ShadowMatrices.java @@ -10,7 +10,7 @@ public class ShadowMatrices { public static Matrix4f createOrthoMatrix(float halfPlaneLength, float nearPlane, float farPlane) { //System.out.println("making a matrix with " + nearPlane + " / " + farPlane + " * " + halfPlaneLength); - return new Matrix4f().setOrthoSymmetric(halfPlaneLength, halfPlaneLength, nearPlane, farPlane); + return new Matrix4f().setOrthoSymmetric(halfPlaneLength * 2, halfPlaneLength * 2, nearPlane, farPlane); } public static Matrix4f createPerspectiveMatrix(float fov) {