fix(iris): implement full GL alpha test (#1673)

This commit is contained in:
Kaiz authored and GitHub committed 2026-04-18 09:12:46 -07:00
1 parent 9c295a1e22
commit 34a6967c71
7 files changed
+66 -16

No files matched your search

@@ -8,6 +8,8 @@ public class StateUpdateNotifiers {
public static ValueUpdateNotifier fogStartNotifier;
public static ValueUpdateNotifier fogEndNotifier;
public static ValueUpdateNotifier fogDensityNotifier;
public static ValueUpdateNotifier alphaFuncNotifier;
public static ValueUpdateNotifier alphaTestNotifier;
public static ValueUpdateNotifier blendFuncNotifier;
public static ValueUpdateNotifier bindTextureNotifier;
public static ValueUpdateNotifier normalTextureChangeNotifier;
@@ -46,7 +46,22 @@ public class CommonTransformer {
// runtime discard using the GLSM-tracked alpha reference value.
if (found.contains(0) && parameters.patch != Patch.COMPOSITE && parameters.patch != Patch.COMPUTE) {
root.injectVariable("uniform float iris_currentAlphaTest;");
root.appendMain("if (iris_FragData0.a <= iris_currentAlphaTest) discard;");
root.injectVariable("uniform int iris_currentAlphaFunc;");
root.injectFunction(
"bool iris_alphaTestPass(float a) {" +
" if (iris_currentAlphaFunc == 7) return true;" + // ALWAYS / disabled
" if (iris_currentAlphaFunc == 0) return false;" + // NEVER
" float qa = round(a * 255.0);" +
" float qr = round(iris_currentAlphaTest * 255.0);" +
" if (iris_currentAlphaFunc == 1) return qa < qr;" + // LESS
" if (iris_currentAlphaFunc == 2) return qa == qr;" + // EQUAL
" if (iris_currentAlphaFunc == 3) return qa <= qr;" + // LEQUAL
" if (iris_currentAlphaFunc == 4) return qa > qr;" + // GREATER
" if (iris_currentAlphaFunc == 5) return qa != qr;" + // NOTEQUAL
" return qa >= qr;" + // GEQUAL (6)
"}"
);
root.appendMain("if (!iris_alphaTestPass(iris_FragData0.a)) discard;");
}
}
}
@@ -2,6 +2,7 @@ package net.coderbot.iris.uniforms;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import net.coderbot.iris.gl.state.FogMode;
import net.coderbot.iris.gl.state.StateUpdateNotifiers;
import net.coderbot.iris.gl.uniform.DynamicUniformHolder;
import org.joml.Vector3d;
import org.joml.Vector4f;
@@ -22,6 +23,12 @@ public class IrisInternalUniforms {
return GLStateManager.getAlphaState().getReference();
}
private static int getEffectiveAlphaFunc() {
if (!GLStateManager.getAlphaTest().isEnabled()) return 7;
final int func = GLStateManager.getAlphaState().getFunction();
return func & 0x7;
}
public static void addFogUniforms(DynamicUniformHolder uniforms, FogMode fogMode) {
uniforms.uniform4f(PER_FRAME, "iris_FogColor", () -> {
final Vector3d color = GLStateManager.getFogState().getFogColor();
@@ -34,7 +41,8 @@ public class IrisInternalUniforms {
.uniform1f(PER_FRAME, "iris_FogDensity", () -> Math.max(0.0F, GLStateManager.getFogState().getDensity()));
uniforms
.uniform1f(PER_FRAME, "iris_currentAlphaTest", IrisInternalUniforms::getEffectiveAlphaRef)
.uniform1f(PER_FRAME, "alphaTestRef", IrisInternalUniforms::getEffectiveAlphaRef);
.uniform1f("iris_currentAlphaTest", IrisInternalUniforms::getEffectiveAlphaRef, StateUpdateNotifiers.alphaTestNotifier)
.uniform1f("alphaTestRef", IrisInternalUniforms::getEffectiveAlphaRef, StateUpdateNotifiers.alphaTestNotifier)
.uniform1i("iris_currentAlphaFunc", IrisInternalUniforms::getEffectiveAlphaFunc, StateUpdateNotifiers.alphaFuncNotifier);
}
}