Skip to content

Commit a2cd5db

Browse files
committed
Backport + Sodium 0.5.12
1 parent 0aeb899 commit a2cd5db

File tree

19 files changed

+262
-214
lines changed

19 files changed

+262
-214
lines changed

build.gradle.kts

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ object Constants {
1010
// https://semver.org/
1111
const val MOD_VERSION: String = "1.7.5"
1212

13-
const val CUSTOM_SODIUM: Boolean = false
14-
const val CUSTOM_SODIUM_NAME: String = ""
13+
const val CUSTOM_SODIUM: Boolean = true
14+
const val CUSTOM_SODIUM_NAME: String = "sodium-fabric-0.5.12-snapshot+mc1.20.1-build.612.jar"
1515

1616
const val IS_SHARED_BETA: Boolean = false
17-
const val ACTIVATE_RENDERDOC: Boolean = false
17+
const val ACTIVATE_RENDERDOC: Boolean = true
1818
const val BETA_TAG: String = "DH Support"
1919
const val BETA_VERSION = 4
2020

@@ -41,7 +41,7 @@ plugins {
4141
// This prevents a lot of issues where the build script can fail randomly because the Fabric Maven server
4242
// is not reachable for some reason, and it makes builds much more reproducible. Observation also shows that it
4343
// really helps to improve startup times on slow connections.
44-
id("fabric-loom") version "1.5.7"
44+
id("fabric-loom") version "1.9.2"
4545
id("org.ajoberstar.grgit") version "5.2.2"
4646
id("com.github.gmazzo.buildconfig") version "5.3.5"
4747
}
@@ -66,6 +66,7 @@ loom {
6666
if (Constants.ACTIVATE_RENDERDOC && DefaultNativePlatform.getCurrentOperatingSystem().isLinux) {
6767
environmentVariable("LD_PRELOAD", "/usr/lib/librenderdoc.so")
6868
}
69+
vmArgs("-Dsodium.checks.issue2561=false")
6970
}
7071
}
7172

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/java/net/irisshaders/iris/compat/dh/DHCompatInternal.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ public DHCompatInternal(IrisRenderingPipeline pipeline, boolean dhShadowEnabled)
9999
}
100100

101101
public static int getDhBlockRenderDistance() {
102-
if (DhApi.Delayed.configs == null) {
102+
if (DhApi.Delayed.configs == null || !dhEnabled) {
103103
// Called before DH has finished setup
104-
return 0;
104+
return Minecraft.getInstance().options.getEffectiveRenderDistance();
105105
}
106106

107107
return DhApi.Delayed.configs.graphics().chunkRenderDistance().getValue() * 16;

src/main/java/net/irisshaders/iris/gl/shader/StandardMacros.java

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.irisshaders.iris.texture.format.TextureFormat;
1313
import net.irisshaders.iris.texture.format.TextureFormatLoader;
1414
import net.minecraft.Util;
15+
import net.minecraft.client.Minecraft;
1516
import org.jetbrains.annotations.Nullable;
1617
import org.lwjgl.opengl.GL11;
1718
import org.lwjgl.opengl.GL20C;
@@ -47,6 +48,7 @@ public static ImmutableList<StringPair> createStandardEnvironmentDefines() {
4748
define(standardDefines, "IRIS_VERSION", getFormattedIrisVersion());
4849
define(standardDefines, "MC_GL_VERSION", getGlVersion(GL20C.GL_VERSION));
4950
define(standardDefines, "MC_GLSL_VERSION", getGlVersion(GL20C.GL_SHADING_LANGUAGE_VERSION));
51+
define(standardDefines, "MC_MIPMAP_LEVEL", String.valueOf(Minecraft.getInstance().options.mipmapLevels().get()));
5052
define(standardDefines, getOsString());
5153
define(standardDefines, getVendor());
5254
define(standardDefines, getRenderer());

src/main/java/net/irisshaders/iris/gl/texture/InternalTextureFormat.java

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.lwjgl.opengl.GL11C;
55
import org.lwjgl.opengl.GL30C;
66
import org.lwjgl.opengl.GL31C;
7+
import org.lwjgl.opengl.GL33C;
78

89
import java.util.Locale;
910
import java.util.Optional;
@@ -76,6 +77,7 @@ public enum InternalTextureFormat {
7677
R3_G3_B2(GL11C.GL_R3_G3_B2, GlVersion.GL_11, PixelFormat.RGB),
7778
RGB5_A1(GL11C.GL_RGB5_A1, GlVersion.GL_11, PixelFormat.RGBA),
7879
RGB10_A2(GL11C.GL_RGB10_A2, GlVersion.GL_11, PixelFormat.RGBA),
80+
RGB10_A2UI(GL33C.GL_RGB10_A2UI, GlVersion.GL_31, PixelFormat.RGBA_INTEGER),
7981
R11F_G11F_B10F(GL30C.GL_R11F_G11F_B10F, GlVersion.GL_30, PixelFormat.RGB),
8082
RGB9_E5(GL30C.GL_RGB9_E5, GlVersion.GL_30, PixelFormat.RGB);
8183

src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumCoreTransformer.java

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package net.irisshaders.iris.pipeline.transform.transformer;
22

3+
import io.github.douira.glsl_transformer.ast.node.Identifier;
34
import io.github.douira.glsl_transformer.ast.node.TranslationUnit;
5+
import io.github.douira.glsl_transformer.ast.node.declaration.TypeAndInitDeclaration;
6+
import io.github.douira.glsl_transformer.ast.node.external_declaration.DeclarationExternalDeclaration;
47
import io.github.douira.glsl_transformer.ast.query.Root;
58
import io.github.douira.glsl_transformer.ast.transform.ASTParser;
69
import net.irisshaders.iris.pipeline.transform.PatchShaderType;
@@ -25,9 +28,27 @@ public static void transform(
2528
root.replaceReferenceExpressions(t, "vaPosition", "_vert_position + _get_draw_translation(_draw_id)");
2629
root.replaceReferenceExpressions(t, "vaColor", "_vert_color");
2730
root.rename("vaNormal", "iris_Normal");
28-
root.replaceReferenceExpressions(t, "vaUV0", "_vert_tex_diffuse_coord");
31+
root.replaceReferenceExpressions(t, "vaUV0", "((_vert_tex_diffuse_coord_bias * u_TexCoordShrink) + _vert_tex_diffuse_coord)");
2932
root.replaceReferenceExpressions(t, "vaUV1", "ivec2(0, 10)");
30-
root.rename("vaUV2", "a_LightCoord");
33+
34+
for (Identifier id : root.identifierIndex.get("vaUV2")) {
35+
TypeAndInitDeclaration initDeclaration = (TypeAndInitDeclaration) id.getAncestor(
36+
2, 0, TypeAndInitDeclaration.class::isInstance);
37+
if (initDeclaration == null) {
38+
continue;
39+
}
40+
DeclarationExternalDeclaration declaration = (DeclarationExternalDeclaration) initDeclaration.getAncestor(
41+
1, 0, DeclarationExternalDeclaration.class::isInstance);
42+
if (declaration == null) {
43+
continue;
44+
}
45+
declaration.detachAndDelete();
46+
initDeclaration.detachAndDelete();
47+
id.detachAndDelete();
48+
49+
}
50+
51+
root.rename("vaUV2", "_vert_tex_light_coord");
3152

3253
root.replaceReferenceExpressions(t, "textureMatrix", "mat4(1.0)");
3354

src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumTransformer.java

+40-10
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static void transform(
3838

3939
if (parameters.inputs.hasTex()) {
4040
root.replaceReferenceExpressions(t, "gl_MultiTexCoord0",
41-
"vec4(_vert_tex_diffuse_coord, 0.0, 1.0)");
41+
"vec4((_vert_tex_diffuse_coord_bias * u_TexCoordShrink) + _vert_tex_diffuse_coord, 0.0, 1.0)");
4242
} else {
4343
root.replaceReferenceExpressions(t, "gl_MultiTexCoord0",
4444
"vec4(0.0, 0.0, 0.0, 1.0)");
@@ -136,20 +136,49 @@ public static void injectVertInit(
136136
// translated from sodium's chunk_vertex.glsl
137137
"vec3 _vert_position;",
138138
"vec2 _vert_tex_diffuse_coord;",
139-
"ivec2 _vert_tex_light_coord;",
139+
"vec2 _vert_tex_diffuse_coord_bias;",
140+
"vec2 _vert_tex_light_coord;",
141+
"const uint POSITION_BITS = 20u;",
142+
"const uint POSITION_MAX_COORD = 1u << POSITION_BITS;",
143+
"const uint POSITION_MAX_VALUE = POSITION_MAX_COORD - 1u;",
144+
145+
"const uint TEXTURE_BITS = 15u;",
146+
"const uint TEXTURE_MAX_COORD = 1u << TEXTURE_BITS;",
147+
"const uint TEXTURE_MAX_VALUE = TEXTURE_MAX_COORD - 1u;",
148+
149+
"const float VERTEX_SCALE = 32.0 / float(POSITION_MAX_COORD);",
150+
"const float VERTEX_OFFSET = -8.0;",
140151
"vec4 _vert_color;",
141152
"uint _draw_id;",
153+
"""
154+
uvec3 _deinterleave_u20x3(uvec2 data) {
155+
uvec3 hi = (uvec3(data.x) >> uvec3(0u, 10u, 20u)) & 0x3FFu;
156+
uvec3 lo = (uvec3(data.y) >> uvec3(0u, 10u, 20u)) & 0x3FFu;
157+
158+
return (hi << 10u) | lo;
159+
}
160+
""",
161+
"""
162+
vec2 _get_texcoord() {
163+
return vec2(a_TexCoord & TEXTURE_MAX_VALUE) / float(TEXTURE_MAX_COORD);
164+
}
165+
""",
166+
"""
167+
vec2 _get_texcoord_bias() {
168+
return mix(vec2(-1.0), vec2(1.0), bvec2(a_TexCoord >> TEXTURE_BITS));
169+
}
170+
""",
142171
"const uint MATERIAL_USE_MIP_OFFSET = 0u;",
143172
"float _material_mip_bias(uint material) {\n" +
144173
" return ((material >> MATERIAL_USE_MIP_OFFSET) & 1u) != 0u ? 0.0f : -4.0f;\n" +
145174
"}",
146175
"void _vert_init() {" +
147-
"_vert_position = (vec3(a_PosId.xyz) * 0.00048828125 + -8.0"
148-
+ ");" +
149-
"_vert_tex_diffuse_coord = (a_TexCoord * " + (1.0f / 32768.0f) + ");" +
150-
"_vert_tex_light_coord = a_LightCoord;" +
176+
"_vert_position = (_deinterleave_u20x3(a_Position) * VERTEX_SCALE) + VERTEX_OFFSET;" +
177+
"_vert_tex_diffuse_coord = _get_texcoord();" +
178+
"_vert_tex_diffuse_coord_bias = _get_texcoord_bias();" +
179+
"_vert_tex_light_coord = vec2(a_LightAndData.xy);" +
151180
"_vert_color = " + separateAo + ";" +
152-
"_draw_id = (a_PosId.w >> 8u) & 0xFFu; }",
181+
"_draw_id = a_LightAndData[3]; }",
153182

154183
"uvec3 _get_relative_chunk_coord(uint pos) {\n" +
155184
" // Packing scheme is defined by LocalSectionIndex\n" +
@@ -158,10 +187,11 @@ public static void injectVertInit(
158187
"vec3 _get_draw_translation(uint pos) {\n" +
159188
" return _get_relative_chunk_coord(pos) * vec3(16.0f);\n" +
160189
"}\n");
161-
addIfNotExists(root, t, tree, "a_PosId", Type.U32VEC4, StorageQualifier.StorageType.IN);
162-
addIfNotExists(root, t, tree, "a_TexCoord", Type.F32VEC2, StorageQualifier.StorageType.IN);
190+
addIfNotExists(root, t, tree, "a_Position", Type.U32VEC2, StorageQualifier.StorageType.IN);
191+
addIfNotExists(root, t, tree, "a_TexCoord", Type.U32VEC2, StorageQualifier.StorageType.IN);
163192
addIfNotExists(root, t, tree, "a_Color", Type.F32VEC4, StorageQualifier.StorageType.IN);
164-
addIfNotExists(root, t, tree, "a_LightCoord", Type.I32VEC2, StorageQualifier.StorageType.IN);
193+
addIfNotExists(root, t, tree, "a_LightAndData", Type.I32VEC4, StorageQualifier.StorageType.IN);
194+
addIfNotExists(root, t, tree, "u_TexCoordShrink", Type.F32VEC2, StorageQualifier.StorageType.UNIFORM);
165195
tree.prependMainFunctionBody(t, "_vert_init();");
166196
}
167197

src/main/java/net/irisshaders/iris/shaderpack/properties/PackShadowDirectives.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.irisshaders.iris.gl.texture.InternalTextureFormat;
88
import net.irisshaders.iris.helpers.OptionalBoolean;
99
import net.irisshaders.iris.shaderpack.parsing.DirectiveHolder;
10+
import net.irisshaders.iris.shadows.ShadowMatrices;
1011
import org.joml.Vector4f;
1112

1213
import java.util.Optional;
@@ -60,8 +61,8 @@ public PackShadowDirectives(ShaderProperties properties) {
6061
// shadowRenderDistanceMul to a nonzero value, since having a high shadow render distance will impact
6162
// performance quite heavily on most systems.
6263
this.distance = 160.0f;
63-
this.nearPlane = 0.05f;
64-
this.farPlane = 256.0f;
64+
this.nearPlane = ShadowMatrices.NEAR;
65+
this.farPlane = ShadowMatrices.FAR;
6566
this.voxelDistance = 0.0f;
6667

6768
// By default, shadows are not culled based on distance from the player. However, pack authors may

src/main/java/net/irisshaders/iris/shadows/ShadowMatrices.java

+4-15
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,12 @@
55
import org.joml.Matrix4f;
66

77
public class ShadowMatrices {
8-
private static final float NEAR = 0.05f;
9-
private static final float FAR = 256.0f;
10-
11-
// NB: These matrices are in column-major order, not row-major order like what you'd expect!
8+
public static final float NEAR = -100.05f;
9+
public static final float FAR = 156.0f;
1210

1311
public static Matrix4f createOrthoMatrix(float halfPlaneLength, float nearPlane, float farPlane) {
14-
return new Matrix4f(
15-
// column 1
16-
1.0f / halfPlaneLength, 0f, 0f, 0f,
17-
// column 2
18-
0f, 1.0f / halfPlaneLength, 0f, 0f,
19-
// column 3
20-
0f, 0f, 2.0f / (nearPlane - farPlane), 0f,
21-
// column 4
22-
0f, 0f, -(farPlane + nearPlane) / (farPlane - nearPlane), 1f
23-
);
12+
//System.out.println("making a matrix with " + nearPlane + " / " + farPlane + " * " + halfPlaneLength);
13+
return new Matrix4f().setOrthoSymmetric(halfPlaneLength * 2, halfPlaneLength * 2, nearPlane, farPlane);
2414
}
2515

2616
public static Matrix4f createPerspectiveMatrix(float fov) {
@@ -50,7 +40,6 @@ public static void createBaselineModelViewMatrix(PoseStack target, float shadowA
5040
target.last().normal().identity();
5141
target.last().pose().identity();
5242

53-
target.last().pose().translate(0.0f, 0.0f, -100.0f);
5443
target.mulPose(Axis.XP.rotationDegrees(90.0F));
5544
target.mulPose(Axis.ZP.rotationDegrees(skyAngle * -360.0f));
5645
target.mulPose(Axis.XP.rotationDegrees(sunPathRotation));

src/main/java/net/irisshaders/iris/shadows/ShadowRenderer.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import net.minecraft.client.renderer.culling.Frustum;
4040
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
4141
import net.minecraft.core.BlockPos;
42+
import net.minecraft.util.Mth;
4243
import net.minecraft.world.entity.Entity;
4344
import net.minecraft.world.level.block.entity.BlockEntity;
4445
import org.joml.Matrix4f;
@@ -439,7 +440,7 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame
439440
// If FOV is not null, the pack wants a perspective based projection matrix. (This is to support legacy packs)
440441
shadowProjection = ShadowMatrices.createPerspectiveMatrix(this.fov);
441442
} else {
442-
shadowProjection = ShadowMatrices.createOrthoMatrix(halfPlaneLength, nearPlane < 0 ? -DHCompat.getRenderDistance() : nearPlane, farPlane < 0 ? DHCompat.getRenderDistance() : farPlane);
443+
shadowProjection = ShadowMatrices.createOrthoMatrix(halfPlaneLength, Mth.equal(nearPlane, -1.0f) ? -DHCompat.getRenderDistance() * 16 : nearPlane, Mth.equal(farPlane, -1.0f) ? DHCompat.getRenderDistance() * 16 : farPlane);
443444
}
444445

445446
IrisRenderSystem.setShadowProjection(shadowProjection);

src/main/java/net/irisshaders/iris/uniforms/MatrixUniforms.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.irisshaders.iris.shaderpack.properties.PackDirectives;
66
import net.irisshaders.iris.shadows.ShadowMatrices;
77
import net.irisshaders.iris.shadows.ShadowRenderer;
8+
import net.minecraft.util.Mth;
89
import org.joml.Matrix4f;
910

1011
import java.util.function.Supplier;
@@ -22,10 +23,9 @@ public static void addMatrixUniforms(UniformHolder uniforms, PackDirectives dire
2223
addShadowMatrix(uniforms, "ModelView", () ->
2324
new Matrix4f(ShadowRenderer.createShadowModelView(directives.getSunPathRotation(), directives.getShadowDirectives().getIntervalSize()).last().pose()));
2425
addShadowMatrix(uniforms, "Projection", () -> ShadowMatrices.createOrthoMatrix(directives.getShadowDirectives().getDistance(),
25-
directives.getShadowDirectives().getNearPlane() < 0 ? -DHCompat.getRenderDistance() : directives.getShadowDirectives().getNearPlane(),
26-
directives.getShadowDirectives().getFarPlane() < 0 ? DHCompat.getRenderDistance() : directives.getShadowDirectives().getFarPlane()));
26+
Mth.equal(directives.getShadowDirectives().getNearPlane(), -1.0f) ? -DHCompat.getRenderDistance() * 16 : directives.getShadowDirectives().getNearPlane(),
27+
Mth.equal(directives.getShadowDirectives().getFarPlane(), -1.0f) ? DHCompat.getRenderDistance() * 16 : directives.getShadowDirectives().getFarPlane()));
2728
}
28-
2929
private static void addMatrix(UniformHolder uniforms, String name, Supplier<Matrix4f> supplier) {
3030
uniforms
3131
.uniformMatrix(PER_FRAME, "gbuffer" + name, supplier)

src/main/resources/fabric.mod.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
"1.20.1"
4242
],
4343
"sodium": [
44-
"0.5.10",
45-
"0.5.11"
44+
"0.5.x"
4645
]
4746
},
4847
"breaks": {

src/sodiumCompatibility/java/net/irisshaders/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import me.jellysquid.mods.sodium.client.gl.shader.GlShader;
66
import me.jellysquid.mods.sodium.client.gl.shader.ShaderType;
77
import me.jellysquid.mods.sodium.client.render.chunk.shader.ChunkFogMode;
8+
import me.jellysquid.mods.sodium.client.render.chunk.shader.ChunkShaderBindingPoints;
89
import me.jellysquid.mods.sodium.client.render.chunk.shader.ChunkShaderOptions;
910
import me.jellysquid.mods.sodium.client.render.chunk.terrain.TerrainRenderPass;
1011
import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType;
@@ -242,10 +243,10 @@ private GlProgram<IrisChunkShaderInterface> createShader(IrisTerrainPass pass, S
242243
return builder.attachShader(vertShader)
243244
.attachShader(fragShader)
244245
// The following 4 attributes are part of Sodium.
245-
.bindAttribute("a_PosId", IrisChunkShaderBindingPoints.ATTRIBUTE_POSITION_ID)
246-
.bindAttribute("a_Color", IrisChunkShaderBindingPoints.ATTRIBUTE_COLOR)
247-
.bindAttribute("a_TexCoord", IrisChunkShaderBindingPoints.ATTRIBUTE_BLOCK_TEXTURE)
248-
.bindAttribute("a_LightCoord", IrisChunkShaderBindingPoints.ATTRIBUTE_LIGHT_TEXTURE)
246+
.bindAttribute("a_Position", ChunkShaderBindingPoints.ATTRIBUTE_POSITION)
247+
.bindAttribute("a_Color", ChunkShaderBindingPoints.ATTRIBUTE_COLOR)
248+
.bindAttribute("a_TexCoord", ChunkShaderBindingPoints.ATTRIBUTE_TEXTURE)
249+
.bindAttribute("a_LightAndData", ChunkShaderBindingPoints.ATTRIBUTE_LIGHT_MATERIAL_INDEX)
249250
.bindAttribute("mc_Entity", IrisChunkShaderBindingPoints.BLOCK_ID)
250251
.bindAttribute("mc_midTexCoord", IrisChunkShaderBindingPoints.MID_TEX_COORD)
251252
.bindAttribute("at_tangent", IrisChunkShaderBindingPoints.TANGENT)

0 commit comments

Comments
 (0)