From a240164c2f87fd557aed3424814d26377e80354f Mon Sep 17 00:00:00 2001 From: Cart <81428538+Cartrigger@users.noreply.github.com> Date: Thu, 5 Sep 2024 03:05:39 -0400 Subject: [PATCH] Multiloader 1.21 lts (#10) Finally..... --------- Co-authored-by: The Judge Co-authored-by: Darien Johnson <84008186+CADIndie@users.noreply.github.com> --- build.gradle | 6 +- .../mixin/client_vr/lwjgl/OpenVRMixin.java | 2 +- .../minecraft/shaders/core/fovreduction.fsh | 2 +- .../assets/minecraft/shaders/core/gsr.fsh | 142 ++++++++++++++++++ .../assets/minecraft/shaders/core/gsr.json | 23 +++ 5 files changed, 170 insertions(+), 5 deletions(-) create mode 100644 common/src/main/resources/assets/minecraft/shaders/core/gsr.fsh create mode 100644 common/src/main/resources/assets/minecraft/shaders/core/gsr.json diff --git a/build.gradle b/build.gradle index 354688b26..3493ec0fe 100644 --- a/build.gradle +++ b/build.gradle @@ -28,9 +28,9 @@ subprojects { // The following line declares the yarn mappings you may select this one as well. // mappings "net.fabricmc:yarn:1.18.2+build.4:v2" implementation("org.lwjgl:lwjgl-openvr:3.3.3") - implementation("org.lwjgl:lwjgl-openvr:3.3.3:natives-linux") - implementation("org.lwjgl:lwjgl-openvr:3.3.3:natives-macos") - implementation("org.lwjgl:lwjgl-openvr:3.3.3:natives-windows") + //implementation("org.lwjgl:lwjgl-openvr:3.3.3:natives-linux") + //implementation("org.lwjgl:lwjgl-openvr:3.3.3:natives-macos") + //implementation("org.lwjgl:lwjgl-openvr:3.3.3:natives-windows") } tasks.withType(JavaCompile) { diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/lwjgl/OpenVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/lwjgl/OpenVRMixin.java index 933b987b4..acbc03957 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/lwjgl/OpenVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/lwjgl/OpenVRMixin.java @@ -72,7 +72,7 @@ public static void create(int tok) { org.vivecraft.client_vr.settings.VRSettings.logger.error("'{}' failed to load, trying IVRCompositor_026", IVRCompositor_Version); VRCompositor = getGenericInterface("IVRCompositor_026", OpenVR.IVRCompositor::new); } - VROverlay = getGenericInterface(IVROverlay_Version, OpenVR.IVROverlay::new); + //VROverlay = getGenericInterface(IVROverlay_Version, OpenVR.IVROverlay::new); // VRResources = getGenericInterface(IVRResources_Version, OpenVR.IVRResources::new); VRRenderModels = getGenericInterface(IVRRenderModels_Version, OpenVR.IVRRenderModels::new); VRExtendedDisplay = getGenericInterface(IVRExtendedDisplay_Version, OpenVR.IVRExtendedDisplay::new); diff --git a/common/src/main/resources/assets/minecraft/shaders/core/fovreduction.fsh b/common/src/main/resources/assets/minecraft/shaders/core/fovreduction.fsh index b81b042e5..65a5640e8 100644 --- a/common/src/main/resources/assets/minecraft/shaders/core/fovreduction.fsh +++ b/common/src/main/resources/assets/minecraft/shaders/core/fovreduction.fsh @@ -58,7 +58,7 @@ void main(){ } if (circle_radius < 0.8){ //arfy barfy - vec2 circle_center = vec2(0.5 + eye*circle_offset, 0.5); + vec2 circle_center = vec2(0.5 + eye*circle_offset, 0.1); vec2 uv = texCoordinates.xy; uv -= circle_center; float dist = sqrt(dot(uv, uv)); diff --git a/common/src/main/resources/assets/minecraft/shaders/core/gsr.fsh b/common/src/main/resources/assets/minecraft/shaders/core/gsr.fsh new file mode 100644 index 000000000..d8c8ec21c --- /dev/null +++ b/common/src/main/resources/assets/minecraft/shaders/core/gsr.fsh @@ -0,0 +1,142 @@ +#version 450 core + +//============================================================================================================ +// +// +// Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved. +// SPDX-License-Identifier: BSD-3-Clause +// +//============================================================================================================ + +precision mediump float; +precision highp int; + +//////////////////////// +// USER CONFIGURATION // +//////////////////////// + +/* +* Operation modes: +* RGBA -> 1 +* RGBY -> 3 +* LERP -> 4 +*/ +#define OperationMode 1 + +#define EdgeThreshold 4.0/255.0 + +#define EdgeSharpness 2.0 + +// #define UseUniformBlock + +//////////////////////// +//////////////////////// +//////////////////////// + +#if defined(UseUniformBlock) +layout (set=0, binding = 0) uniform UniformBlock +{ + highp vec4 ViewportInfo[1]; +}; +layout(set = 0, binding = 1) uniform mediump sampler2D Sampler0; +#else +uniform vec4 ViewportInfo[1]; +uniform sampler2D Sampler0; +#endif + +in vec2 texCoordinates; +out vec4 fragColor; + +float fastLanczos2(float x) +{ + float wA = x-4.0; + float wB = x*wA-wA; + wA *= wA; + return wB*wA; +} +vec2 weightY(float dx, float dy,float c, float std) +{ + float x = ((dx*dx)+(dy* dy))* 0.55 + clamp(abs(c)*std, 0.0, 1.0); + float w = fastLanczos2(x); + return vec2(w, w * c); +} + +void main() +{ + const int mode = OperationMode; + float edgeThreshold = EdgeThreshold; + float edgeSharpness = EdgeSharpness; + + vec4 color; + if(mode == 1) + color.xyz = textureLod(Sampler0,texCoordinates.xy,0.0).xyz; + else + color.xyzw = textureLod(Sampler0,texCoordinates.xy,0.0).xyzw; + + float xCenter; + xCenter = abs(texCoordinates.x+-0.5); + float yCenter; + yCenter = abs(texCoordinates.y+-0.5); + + //todo: config the SR region based on needs + //if ( mode!=4 && xCenter*xCenter+yCenter*yCenter<=0.4 * 0.4) + if ( mode!=4) + { + vec2 imgCoord = ((texCoordinates.xy*ViewportInfo[0].zw)+vec2(-0.5,0.5)); + vec2 imgCoordPixel = floor(imgCoord); + vec2 coord = (imgCoordPixel*ViewportInfo[0].xy); + vec2 pl = (imgCoord+(-imgCoordPixel)); + vec4 left = textureGather(Sampler0,coord, mode); + + float edgeVote = abs(left.z - left.y) + abs(color[mode] - left.y) + abs(color[mode] - left.z) ; + if(edgeVote > edgeThreshold) + { + coord.x += ViewportInfo[0].x; + + vec4 right = textureGather(Sampler0,coord + vec2(ViewportInfo[0].x, 0.0), mode); + vec4 upDown; + upDown.xy = textureGather(Sampler0,coord + vec2(0.0, -ViewportInfo[0].y),mode).wz; + upDown.zw = textureGather(Sampler0,coord+ vec2(0.0, ViewportInfo[0].y), mode).yx; + + float mean = (left.y+left.z+right.x+right.w)*0.25; + left = left - vec4(mean); + right = right - vec4(mean); + upDown = upDown - vec4(mean); + color.w =color[mode] - mean; + + float sum = (((((abs(left.x)+abs(left.y))+abs(left.z))+abs(left.w))+(((abs(right.x)+abs(right.y))+abs(right.z))+abs(right.w)))+(((abs(upDown.x)+abs(upDown.y))+abs(upDown.z))+abs(upDown.w))); + float std = 2.181818/sum; + + vec2 aWY = weightY(pl.x, pl.y+1.0, upDown.x,std); + aWY += weightY(pl.x-1.0, pl.y+1.0, upDown.y,std); + aWY += weightY(pl.x-1.0, pl.y-2.0, upDown.z,std); + aWY += weightY(pl.x, pl.y-2.0, upDown.w,std); + aWY += weightY(pl.x+1.0, pl.y-1.0, left.x,std); + aWY += weightY(pl.x, pl.y-1.0, left.y,std); + aWY += weightY(pl.x, pl.y, left.z,std); + aWY += weightY(pl.x+1.0, pl.y, left.w,std); + aWY += weightY(pl.x-1.0, pl.y-1.0, right.x,std); + aWY += weightY(pl.x-2.0, pl.y-1.0, right.y,std); + aWY += weightY(pl.x-2.0, pl.y, right.z,std); + aWY += weightY(pl.x-1.0, pl.y, right.w,std); + + float finalY = aWY.y/aWY.x; + + float maxY = max(max(left.y,left.z),max(right.x,right.w)); + float minY = min(min(left.y,left.z),min(right.x,right.w)); + finalY = clamp(edgeSharpness*finalY, minY, maxY); + + float deltaY = finalY -color.w; + + //smooth high contrast input + deltaY = clamp(deltaY, -23.0 / 255.0, 23.0 / 255.0); + + color.x = clamp((color.x+deltaY),0.0,1.0); + color.y = clamp((color.y+deltaY),0.0,1.0); + color.z = clamp((color.z+deltaY),0.0,1.0); + } + } + + color.w = 1.0; //assume alpha channel is not used + fragColor.xyzw = color; +} diff --git a/common/src/main/resources/assets/minecraft/shaders/core/gsr.json b/common/src/main/resources/assets/minecraft/shaders/core/gsr.json new file mode 100644 index 000000000..2282ad252 --- /dev/null +++ b/common/src/main/resources/assets/minecraft/shaders/core/gsr.json @@ -0,0 +1,23 @@ +{ + "blend": { + "func": "add", + "srcrgb": "srcalpha", + "dstrgb": "1-srcalpha" + }, + "vertex": "passthrough", + "fragment": "gsr", + "attributes": ["Position", "UV0"], + "samplers": [ + { + "name": "Sampler0" + } + ], + "uniforms": [ + { + "name": "ViewportInfo", + "type": "float", + "count": 4, + "values": [0.0, 0.0, 1.0, 1.0] + } + ] +}