Skip to content

Commit c1bc46a

Browse files
committed
Initial attempt at Nvidium-style Iris support
This does work! But this deserves a photosensitivity/cave worm warning for those who want to mess with it
1 parent 6b2f1b5 commit c1bc46a

File tree

6 files changed

+119
-43
lines changed

6 files changed

+119
-43
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
longview = "1.0.1"
2+
longview = "1.1.0"
33

44
minecraft = "26.1"
55

mod/src/main/java/page/langeweile/longview/impl/LongviewImpl.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
11
package page.langeweile.longview.impl;
22

3+
import org.lwjgl.opengl.GL45;
4+
import page.langeweile.longview.mixin.reverse_z.compat.IrisApiAccessor;
5+
36
public class LongviewImpl {
4-
//private OperationMode operationMode = OperationMode.LONGVIEW;
7+
public static boolean isZZeroToOne() {
8+
return !isIrisActive();
9+
}
10+
11+
public static boolean isZReversed() {
12+
return !isIrisActive();
13+
}
514

6-
public static Mode getMode() {
7-
return Mode.LONGVIEW;
15+
private static boolean isIrisActive() {
16+
try {
17+
return ((IrisApiAccessor) LongviewImpl.getClass("net.irisshaders.iris.api.v0.IrisApi").getMethod("getInstance").invoke(null)).callIsShaderPackInUse();
18+
} catch (Exception e) {
19+
e.printStackTrace();
20+
return false;
21+
}
822
}
923

10-
public static boolean isZZeroToOne() {
11-
return true;
24+
private static Class<?> getClass(String className) {
25+
try {
26+
return Class.forName(className);
27+
} catch (ClassNotFoundException e) {
28+
return null;
29+
}
1230
}
1331

14-
public static boolean isZReversed() {
15-
return true;
32+
private static void toggleZZeroToOne(boolean zZeroToOne) {
33+
if (zZeroToOne) {
34+
GL45.glClipControl(GL45.GL_LOWER_LEFT, GL45.GL_ZERO_TO_ONE);
35+
} else {
36+
GL45.glClipControl(GL45.GL_LOWER_LEFT, GL45.GL_NEGATIVE_ONE_TO_ONE);
37+
}
1638
}
1739

1840
public enum Mode {

mod/src/main/java/page/langeweile/longview/mixin/reverse_z/DepthStencilStateMixin.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,39 @@
55
*/
66
package page.langeweile.longview.mixin.reverse_z;
77

8-
import com.llamalad7.mixinextras.sugar.Local;
9-
import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef;
10-
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
8+
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
119
import com.mojang.blaze3d.pipeline.DepthStencilState;
1210
import com.mojang.blaze3d.platform.CompareOp;
1311
import org.spongepowered.asm.mixin.Mixin;
1412
import org.spongepowered.asm.mixin.injection.At;
15-
import org.spongepowered.asm.mixin.injection.Inject;
16-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1713
import page.langeweile.longview.impl.LongviewImpl;
1814

1915
@Mixin(DepthStencilState.class)
2016
public abstract class DepthStencilStateMixin {
21-
@Inject(method = "<init>(Lcom/mojang/blaze3d/platform/CompareOp;ZFF)V", at = @At("HEAD"))
22-
private static void modifyCompareOp(
23-
CallbackInfo ci,
24-
@Local(argsOnly = true) LocalRef<CompareOp> depthTest,
25-
@Local(argsOnly = true, ordinal = 0) LocalFloatRef depthBiasScaleFactor,
26-
@Local(argsOnly = true, ordinal = 1) LocalFloatRef depthBiasConstant
27-
) {
28-
if (!LongviewImpl.isZReversed()) return;
29-
30-
depthTest.set(
31-
switch (depthTest.get()) {
17+
@ModifyReturnValue(method = "depthTest", at = @At("TAIL"))
18+
private CompareOp modifyDepthTest(CompareOp original) {
19+
return LongviewImpl.isZReversed()
20+
? switch (original) {
3221
case LESS_THAN -> CompareOp.GREATER_THAN;
3322
case LESS_THAN_OR_EQUAL -> CompareOp.GREATER_THAN_OR_EQUAL;
3423
case GREATER_THAN_OR_EQUAL -> CompareOp.LESS_THAN_OR_EQUAL;
3524
case GREATER_THAN -> CompareOp.LESS_THAN;
36-
default -> depthTest.get();
25+
default -> original;
3726
}
38-
);
39-
// The following methods ensure that things like text on glowing signs won't be ordered the wrong way
40-
depthBiasScaleFactor.set(-depthBiasScaleFactor.get());
41-
depthBiasConstant.set(-depthBiasConstant.get());
27+
: original;
28+
}
29+
30+
@ModifyReturnValue(method = "depthBiasConstant", at = @At("TAIL"))
31+
private float modifyDepthBiasConstant(float original) {
32+
return LongviewImpl.isZReversed()
33+
? -original
34+
: original;
35+
}
36+
37+
@ModifyReturnValue(method = "depthBiasScaleFactor", at = @At("TAIL"))
38+
private float modifyDepthBiasScaleFactor(float original) {
39+
return LongviewImpl.isZReversed()
40+
? -original
41+
: original;
4242
}
4343
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*/
6+
package page.langeweile.longview.mixin.reverse_z.compat;
7+
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.gen.Invoker;
10+
11+
@Mixin(targets = "net.irisshaders.iris.api.v0.IrisApi")
12+
public interface IrisApiAccessor {
13+
@Invoker
14+
boolean callIsShaderPackInUse();
15+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*/
6+
package page.langeweile.longview.mixin.reverse_z.compat;
7+
8+
import net.minecraft.client.Minecraft;
9+
import org.lwjgl.opengl.GL45;
10+
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.injection.At;
12+
import org.spongepowered.asm.mixin.injection.Inject;
13+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
14+
import page.langeweile.longview.impl.LongviewImpl;
15+
16+
@Mixin(targets = "net.irisshaders.iris.pipeline.PipelineManager")
17+
public class PipelineManagerMixin {
18+
@Inject(
19+
method = "preparePipeline",
20+
at = @At(
21+
value = "INVOKE_ASSIGN",
22+
target = "Lnet/irisshaders/iris/shaderpack/materialmap/WorldRenderingSettings;isReloadRequired()Z"
23+
),
24+
cancellable = true
25+
)
26+
private void a(CallbackInfoReturnable<?> cir) {
27+
if (LongviewImpl.isZZeroToOne()) {
28+
GL45.glClipControl(GL45.GL_LOWER_LEFT, GL45.GL_ZERO_TO_ONE);
29+
} else {
30+
GL45.glClipControl(GL45.GL_LOWER_LEFT, GL45.GL_NEGATIVE_ONE_TO_ONE);
31+
}
32+
33+
var target = Minecraft.getInstance().getMainRenderTarget();
34+
target.resize(target.width, target.height);
35+
System.out.println(LongviewImpl.isZZeroToOne());
36+
}
37+
}
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
2-
"required": true,
3-
"minVersion": "0.8",
4-
"package": "page.langeweile.longview.mixin",
5-
"compatibilityLevel": "JAVA_25",
6-
"client": [
7-
"reverse_z.CommandEncoderMixin",
8-
"reverse_z.DepthStencilStateMixin",
9-
"reverse_z.MinecraftMixin",
10-
"reverse_z.ProjectionMixin",
11-
"zero_to_one.GlDeviceMixin"
12-
],
13-
"injectors": {
14-
"defaultRequire": 1
15-
}
2+
"required": true,
3+
"minVersion": "0.8",
4+
"package": "page.langeweile.longview.mixin",
5+
"compatibilityLevel": "JAVA_25",
6+
"client": [
7+
"reverse_z.compat.IrisApiAccessor",
8+
"reverse_z.compat.PipelineManagerMixin",
9+
"reverse_z.CommandEncoderMixin",
10+
"reverse_z.DepthStencilStateMixin",
11+
"reverse_z.MinecraftMixin",
12+
"reverse_z.ProjectionMixin",
13+
"zero_to_one.GlDeviceMixin"
14+
],
15+
"injectors": {
16+
"defaultRequire": 1
17+
}
1618
}

0 commit comments

Comments
 (0)