From 9e496131b5e47f3d4f86323af7cd3f266632f751 Mon Sep 17 00:00:00 2001 From: fayer3 Date: Sun, 15 Sep 2024 18:21:54 +0200 Subject: [PATCH] fix optifine compatibility --- .../org/vivecraft/client_vr/VRTextureTarget.java | 13 +++++++++---- .../vivecraft/client_vr/provider/VRRenderer.java | 6 +++--- .../client_vr/renderer/GameRendererVRMixin.java | 10 ++++++---- .../optifine/mixin/ShadersRenderVRMixin.java | 3 ++- gradle.properties | 2 +- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client_vr/VRTextureTarget.java b/common/src/main/java/org/vivecraft/client_vr/VRTextureTarget.java index 88f1bcf07..150e848bf 100644 --- a/common/src/main/java/org/vivecraft/client_vr/VRTextureTarget.java +++ b/common/src/main/java/org/vivecraft/client_vr/VRTextureTarget.java @@ -15,11 +15,16 @@ public VRTextureTarget(String name, int width, int height, boolean usedepth, boo RenderSystem.assertOnRenderThreadOrInit(); ((RenderTargetExtension) this).vivecraft$setTextid(texid); ((RenderTargetExtension) this).vivecraft$isLinearFilter(linearFilter); - ((RenderTargetExtension) this).vivecraft$setUseStencil(useStencil); - this.resize(width, height, onMac); - if (useStencil) { - Xplat.enableRenderTargetStencil(this); + + // need to set this first, because the forge/neoforge stencil enabled does a resize + this.viewWidth = width; + this.viewHeight = height; + + if (useStencil && !Xplat.enableRenderTargetStencil(this)) { + // use our stencil only if the modloader doesn't support it + ((RenderTargetExtension) this).vivecraft$setUseStencil(true); } + this.resize(width, height, onMac); this.setClearColor(0, 0, 0, 0); } diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java b/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java index d79669838..858f83444 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java @@ -488,11 +488,11 @@ public void setupRenderConfiguration() throws Exception { Tuple cameraSize = getCameraTextureSize(eyeFBWidth, eyeFBHeight); // main render target - ((RenderTargetExtension) WorldRenderPass.stereoXR.target).vivecraft$setUseStencil(dataholder.vrSettings.vrUseStencil); - WorldRenderPass.stereoXR.resize(eyeFBWidth, eyeFBHeight); if (dataholder.vrSettings.vrUseStencil) { - Xplat.enableRenderTargetStencil(WorldRenderPass.stereoXR.target); + ((RenderTargetExtension) WorldRenderPass.stereoXR.target) + .vivecraft$setUseStencil(!Xplat.enableRenderTargetStencil(WorldRenderPass.stereoXR.target)); } + WorldRenderPass.stereoXR.resize(eyeFBWidth, eyeFBHeight); if (dataholder.vrSettings.useFsaa) { this.fsaaFirstPassResultFBO.resize(eyew, eyeFBHeight, Minecraft.ON_OSX); } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java index ef0129f0b..3464bb4b5 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java @@ -1,6 +1,8 @@ package org.vivecraft.mixin.client_vr.renderer; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; @@ -529,13 +531,13 @@ public abstract class GameRendererVRMixin } } - @ModifyVariable(at = @At(value = "STORE", ordinal = 1), ordinal = 4, method = "renderLevel") - public float vivecraft$reduceNauseaAffect(float oldVal) { + @WrapOperation(at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;lerp(FFF)F"), method = "renderLevel") + public float vivecraft$reduceNauseaAffect(float partialTick, float oldVal, float newVal, Operation original) { if (!RenderPassType.isVanilla()) { // scales down the effect from (1,0.65) to (1,0.9) - return 1f - (1f - oldVal) * 0.25f; + return original.call(partialTick, oldVal, newVal) * 0.4F; } else { - return oldVal; + return original.call(partialTick, oldVal, newVal); } } diff --git a/common/src/main/java/org/vivecraft/mod_compat_vr/optifine/mixin/ShadersRenderVRMixin.java b/common/src/main/java/org/vivecraft/mod_compat_vr/optifine/mixin/ShadersRenderVRMixin.java index 2dad84b33..924344c30 100644 --- a/common/src/main/java/org/vivecraft/mod_compat_vr/optifine/mixin/ShadersRenderVRMixin.java +++ b/common/src/main/java/org/vivecraft/mod_compat_vr/optifine/mixin/ShadersRenderVRMixin.java @@ -1,5 +1,6 @@ package org.vivecraft.mod_compat_vr.optifine.mixin; +import com.llamalad7.mixinextras.sugar.Local; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; @@ -48,7 +49,7 @@ public static void updateActiveRenderInfo(Camera activeRenderInfo, Minecraft mc, } @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;getInstance()Lnet/minecraft/client/Minecraft;", remap = true), method = "renderShadowMap", remap = false, cancellable = true) - private static void vivecraft$shadowsOnlyOnce(GameRenderer gameRenderer, Camera activeRenderInfo, int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { + private static void vivecraft$shadowsOnlyOnce(CallbackInfo ci, @Local(argsOnly = true) Camera activeRenderInfo, @Local(argsOnly = true) float partialTicks) { if (!RenderPassType.isVanilla() && ClientDataHolderVR.getInstance().currentPass != RenderPass.LEFT) { if (vivecraft$setCameraShadow == null) { try { diff --git a/gradle.properties b/gradle.properties index f1c52491e..7a3f77830 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ minecraft_version=1.21 enabled_platforms=fabric,forge,neoforge archives_base_name=vivecraft -mod_version=1.1.12-b1 +mod_version=1.1.12-b2 maven_group=org.vivecraft architectury_version=12.0.26