Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buildSrc/src/main/groovy/multiloader-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ repositories {
dependencies {
compileOnly "maven.modrinth:lithium:mc1.21.1-0.15.3-neoforge"
compileOnly "maven.modrinth:sodium:$sodium_version"
compileOnly "maven.modrinth:iris:$iris_version"
compileOnly "maven.modrinth:distanthorizons:$distant_horizons_version"
compileOnly("cc.tweaked:cc-tweaked-$minecraft_version-forge:$cc_tweaked_version")
compileOnly("io.github.mortuusars.exposure:exposure-${minecraft_version}-neoforge:${exposure_version}") { transitive = false }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package dev.ryanhcode.sable.mixin.compatibility.iris;

import com.mojang.blaze3d.shaders.Uniform;
import dev.ryanhcode.sable.mixinterface.compatibility.iris.ExtendedShaderExtension;
import net.irisshaders.iris.pipeline.programs.ExtendedShader;
import net.minecraft.client.renderer.ShaderInstance;
import org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;

@Mixin(ExtendedShader.class)
public class ExtendedShaderMixin implements ExtendedShaderExtension {

@Shadow
@Final
private Uniform modelViewInverse;

@Shadow
@Final
private Uniform normalMatrix;

@Shadow
@Final
private Matrix4f tempMatrix4f;

@Shadow
@Final
private Matrix3f tempMatrix3f;

@Shadow
@Final
private float[] tempFloats;

@Shadow
@Final
private float[] tempFloats2;

@Override
@Unique
public void sable$refreshModelViewDerivedMatrices() {
final var modelView = ((ShaderInstance) (Object) this).MODEL_VIEW_MATRIX;

if (modelView != null) {
if (this.modelViewInverse != null) {
this.modelViewInverse.set(this.tempMatrix4f.set(modelView.getFloatBuffer()).invert().get(this.tempFloats));
this.modelViewInverse.upload();
}

if (this.normalMatrix != null) {
this.normalMatrix.set(this.tempMatrix3f.set(this.tempMatrix4f.set(modelView.getFloatBuffer())).invert().transpose().get(this.tempFloats2));
this.normalMatrix.upload();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dev.ryanhcode.sable.mixinterface.compatibility.iris;

public interface ExtendedShaderExtension {
void sable$refreshModelViewDerivedMatrices();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dev.ryanhcode.sable.companion.math.JOMLConversion;
import dev.ryanhcode.sable.companion.math.Pose3dc;
import dev.ryanhcode.sable.mixin.sublevel_render.RenderSectionAccessor;
import dev.ryanhcode.sable.mixinterface.compatibility.iris.ExtendedShaderExtension;
import dev.ryanhcode.sable.mixinterface.sublevel_render.vanilla.RenderSectionExtension;
import dev.ryanhcode.sable.sublevel.ClientSubLevel;
import dev.ryanhcode.sable.sublevel.render.SubLevelRenderData;
Expand Down Expand Up @@ -319,6 +320,10 @@ public void renderChunkedSubLevel(final RenderType layer, final ShaderInstance s
if (shader.MODEL_VIEW_MATRIX != null) {
shader.MODEL_VIEW_MATRIX.set(modelView.mul(transform, MODEL_MATRIX));
shader.MODEL_VIEW_MATRIX.upload();

if (shader instanceof final ExtendedShaderExtension ext) {
ext.sable$refreshModelViewDerivedMatrices();
}
}

// TODO: sorting
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/sable.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"camera.new_camera_types.MinecraftMixin",
"clip_overwrite.ClientLevelMixin",
"clip_overwrite.GameRendererMixin",
"compatibility.iris.ExtendedShaderMixin",
"config.GameRendererAccessor",
"debug_render.DebugRendererMixin",
"debug_render.DebugScreenOverlayMixin",
Expand Down