Skip to content

Commit

Permalink
todo
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Jan 18, 2025
1 parent 76357f9 commit ded7d69
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
5 changes: 4 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down Expand Up @@ -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;",
Expand All @@ -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;",
Expand Down Expand Up @@ -171,15 +171,16 @@ 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" +
" return ((material >> MATERIAL_USE_MIP_OFFSET) & 1u) != 0u ? 0.0f : -4.0f;\n" +
"}",
"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);" : "") +
Expand Down
3 changes: 2 additions & 1 deletion fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit ded7d69

Please sign in to comment.