From ded7d69213c6865b803a4fcc48f3f8e5eb0b02f6 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sat, 18 Jan 2025 13:18:58 -0800 Subject: [PATCH] todo --- build.gradle.kts | 5 ++++- common/build.gradle.kts | 3 ++- .../iris/pipeline/programs/SodiumShader.java | 21 +++++++++++++++++++ .../transformer/SodiumTransformer.java | 11 +++++----- fabric/build.gradle.kts | 3 ++- neoforge/build.gradle.kts | 3 ++- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ce8632cf8e..8b006dd612 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,12 +9,15 @@ val NEOFORGE_VERSION by extra { "21.1.58" } val FABRIC_LOADER_VERSION by extra { "0.16.10" } val FABRIC_API_VERSION by extra { "0.103.0+1.21.1" } +val SODIUM_DEPENDENCY_FABRIC by extra { files(rootDir.resolve("custom_sodium").resolve("sodium-fabric-0.6.7-snapshot+mc1.21.1-local.jar"))} +val SODIUM_DEPENDENCY_NEO by extra { "maven.modrinth:sodium:mc1.21.1-0.6.1-neoforge" } + // This value can be set to null to disable Parchment. // TODO: Re-add Parchment val PARCHMENT_VERSION by extra { null } // https://semver.org/ -val MOD_VERSION by extra { "1.8.1" } +val MOD_VERSION by extra { "1.8.5" } allprojects { apply(plugin = "java") diff --git a/common/build.gradle.kts b/common/build.gradle.kts index b5f6c45224..52b28f6e12 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -24,6 +24,7 @@ repositories { val MINECRAFT_VERSION: String by rootProject.extra val PARCHMENT_VERSION: String? by rootProject.extra val FABRIC_LOADER_VERSION: String by rootProject.extra +val SODIUM_DEPENDENCY_FABRIC: Any by rootProject.extra val FABRIC_API_VERSION: String by rootProject.extra sourceSets.create("desktop") @@ -58,7 +59,7 @@ dependencies { modCompileOnly("net.fabricmc.fabric-api:fabric-renderer-api-v1:3.2.9+1172e897d7") - modImplementation("maven.modrinth", "sodium", "mc1.21.1-0.6.1-fabric") + modImplementation(SODIUM_DEPENDENCY_FABRIC) modCompileOnly("org.antlr:antlr4-runtime:4.13.1") modCompileOnly("io.github.douira:glsl-transformer:2.0.1") modCompileOnly("org.anarres:jcpp:1.4.14") diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumShader.java b/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumShader.java index 43835850d3..2e858dd740 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumShader.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/programs/SodiumShader.java @@ -3,10 +3,12 @@ import com.google.common.collect.ImmutableSet; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; +import net.caffeinemc.mods.sodium.client.gl.shader.uniform.GlUniformFloat2v; import net.caffeinemc.mods.sodium.client.gl.shader.uniform.GlUniformFloat3v; import net.caffeinemc.mods.sodium.client.gl.shader.uniform.GlUniformMatrix4f; import net.caffeinemc.mods.sodium.client.render.chunk.shader.ChunkShaderInterface; import net.caffeinemc.mods.sodium.client.render.chunk.shader.ShaderBindingContext; +import net.caffeinemc.mods.sodium.mixin.core.render.texture.TextureAtlasAccessor; import net.irisshaders.iris.gl.IrisRenderSystem; import net.irisshaders.iris.gl.blending.BlendModeOverride; import net.irisshaders.iris.gl.blending.BufferBlendOverride; @@ -22,6 +24,7 @@ import net.irisshaders.iris.uniforms.custom.CustomUniforms; import net.irisshaders.iris.vertices.ImmediateState; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.TextureAtlas; import org.joml.Matrix3f; import org.joml.Matrix4f; import org.joml.Matrix4fc; @@ -32,12 +35,15 @@ import java.util.function.Supplier; public class SodiumShader implements ChunkShaderInterface { + private static final int SUB_TEXEL_PRECISION_BITS = 5; + private final GlUniformMatrix4f uniformModelViewMatrix; private final GlUniformMatrix4f uniformModelViewMatrixInv; private final GlUniformMatrix4f uniformProjectionMatrix; private final GlUniformMatrix4f uniformProjectionMatrixInv; private final GlUniformMatrix3f uniformNormalMatrix; private final GlUniformFloat3v uniformRegionOffset; + private final GlUniformFloat2v uniformTexCoordShrink; private final ProgramImages images; private final ProgramSamplers samplers; private final ProgramUniforms uniforms; @@ -58,6 +64,7 @@ public SodiumShader(IrisRenderingPipeline pipeline, SodiumPrograms.Pass pass, Sh this.uniformProjectionMatrix = context.bindUniformOptional("iris_ProjectionMatrix", GlUniformMatrix4f::new); this.uniformProjectionMatrixInv = context.bindUniformOptional("iris_ProjectionMatrixInv", GlUniformMatrix4f::new); this.uniformRegionOffset = context.bindUniformOptional("u_RegionOffset", GlUniformFloat3v::new); + this.uniformTexCoordShrink = context.bindUniformOptional("u_TexCoordShrink", GlUniformFloat2v::new); this.alphaTest = alphaTest; this.containsTessellation = containsTessellation; @@ -143,6 +150,20 @@ public void setupState() { images.update(); bindTextures(); + var textureAtlas = (TextureAtlasAccessor) Minecraft.getInstance() + .getTextureManager() + .getTexture(TextureAtlas.LOCATION_BLOCKS); + + // There is a limited amount of sub-texel precision when using hardware texture sampling. The mapped texture + // area must be "shrunk" by at least one sub-texel to avoid bleed between textures in the atlas. And since we + // offset texture coordinates in the vertex format by one texel, we also need to undo that here. + double subTexelPrecision = (1 << SUB_TEXEL_PRECISION_BITS); + double subTexelOffset = 1.0f / (1 << 15); + this.uniformTexCoordShrink.set( + (float) (subTexelOffset + ((1.0D / textureAtlas.getWidth()) / subTexelPrecision)), + (float) (subTexelOffset + ((1.0D / textureAtlas.getHeight()) / subTexelPrecision)) + ); + if (containsTessellation) { ImmediateState.usingTessellation = true; } diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumTransformer.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumTransformer.java index 460d1313c9..656b6191a1 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumTransformer.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumTransformer.java @@ -37,9 +37,10 @@ public static void transform( // Alias of gl_MultiTexCoord1 on 1.15+ for OptiFine // See https://github.com/IrisShaders/Iris/issues/1149 root.rename("gl_MultiTexCoord2", "gl_MultiTexCoord1"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "uniform vec2 u_TexCoordShrink;"); root.replaceReferenceExpressions(t, "gl_MultiTexCoord0", - "vec4(_vert_tex_diffuse_coord, 0.0, 1.0)"); + "vec4(_vert_tex_diffuse_coord - (_vert_tex_diffuse_coord_bias * u_TexCoordShrink), 0.0, 1.0)"); root.replaceReferenceExpressions(t, "gl_MultiTexCoord1", "vec4(_vert_tex_light_coord, 0.0, 1.0)"); @@ -118,6 +119,7 @@ public static void injectVertInit( // translated from sodium's chunk_vertex.glsl "vec3 _vert_position;", "vec2 _vert_tex_diffuse_coord;", + "vec2 _vert_tex_diffuse_coord_bias;", "vec2 _vert_tex_light_coord;", "vec4 _vert_color;", "const uint POSITION_BITS = 20u;", @@ -130,8 +132,6 @@ public static void injectVertInit( "const float VERTEX_SCALE = 32.0 / POSITION_MAX_COORD;", "const float VERTEX_OFFSET = -8.0;", - "const float TEXTURE_FUZZ_AMOUNT = 1.0 / 64.0;", - "const float TEXTURE_GROW_FACTOR = (1.0 - TEXTURE_FUZZ_AMOUNT) / TEXTURE_MAX_COORD;", "uint _draw_id;", "vec3 irs_Normal;", "vec4 irs_Tangent;", @@ -171,7 +171,7 @@ vec2 _get_texcoord() { """, """ vec2 _get_texcoord_bias() { - return mix(vec2(-TEXTURE_GROW_FACTOR), vec2(TEXTURE_GROW_FACTOR), bvec2(a_TexCoord >> TEXTURE_BITS)); + return mix(vec2(-1.0), vec2(1.0), bvec2(a_TexCoord >> TEXTURE_BITS)); } """, "float _material_mip_bias(uint material) {\n" + @@ -179,7 +179,8 @@ vec2 _get_texcoord_bias() { "}", "void _vert_init() {" + "_vert_position = ((_deinterleave_u20x3(a_Position) * VERTEX_SCALE) + VERTEX_OFFSET);" + - "_vert_tex_diffuse_coord = _get_texcoord() + _get_texcoord_bias();" + + "_vert_tex_diffuse_coord = _get_texcoord();" + + "_vert_tex_diffuse_coord_bias = _get_texcoord_bias();" + "_vert_tex_light_coord = vec2(a_LightAndData.xy);" + "_vert_color = a_Color;" + (needsNormal ? "irs_Normal = oct_to_vec3(iris_Normal.xy);" : "") + diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 5063a94684..7c7f377405 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -8,6 +8,7 @@ val MINECRAFT_VERSION: String by rootProject.extra val PARCHMENT_VERSION: String? by rootProject.extra val FABRIC_LOADER_VERSION: String by rootProject.extra val FABRIC_API_VERSION: String by rootProject.extra +val SODIUM_DEPENDENCY_FABRIC: Any by rootProject.extra val MOD_VERSION: String by rootProject.extra repositories { @@ -63,7 +64,7 @@ dependencies { addRuntimeFabricModule("fabric-rendering-fluids-v1") addRuntimeFabricModule("fabric-resource-loader-v0") - modImplementation("maven.modrinth", "sodium", "mc1.21.1-0.6.1-fabric") + modImplementation(SODIUM_DEPENDENCY_FABRIC) implementAndInclude("org.antlr:antlr4-runtime:4.13.1") implementAndInclude("io.github.douira:glsl-transformer:2.0.1") implementAndInclude("org.anarres:jcpp:1.4.14") diff --git a/neoforge/build.gradle.kts b/neoforge/build.gradle.kts index e9a3e5b4fa..f5bfc9a776 100644 --- a/neoforge/build.gradle.kts +++ b/neoforge/build.gradle.kts @@ -7,6 +7,7 @@ plugins { val MINECRAFT_VERSION: String by rootProject.extra val PARCHMENT_VERSION: String? by rootProject.extra val NEOFORGE_VERSION: String by rootProject.extra +val SODIUM_DEPENDENCY_NEO: String by rootProject.extra val MOD_VERSION: String by rootProject.extra base { @@ -119,7 +120,7 @@ dependencies { includeDep("org.sinytra.forgified-fabric-api:fabric-rendering-data-attachment-v1:0.3.48+73761d2e19") includeDep("org.sinytra.forgified-fabric-api:fabric-block-view-api-v2:1.0.10+9afaaf8c19") - implementation("maven.modrinth", "sodium", "mc1.21.1-0.6.1-neoforge") + implementation(SODIUM_DEPENDENCY_NEO) includeAdditional("io.github.douira:glsl-transformer:2.0.1") includeAdditional("org.anarres:jcpp:1.4.14") }