mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-04-14 02:39:00 +02:00
move in tree, remove sgsr dep
This commit is contained in:
parent
79e2504216
commit
2146911d51
7 changed files with 267 additions and 240 deletions
|
|
@ -1,192 +0,0 @@
|
|||
diff --git a/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag b/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
|
||||
index 7074999..2db04b3 100644
|
||||
--- a/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
|
||||
+++ b/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
|
||||
@@ -1,4 +1,4 @@
|
||||
-#version 300 es
|
||||
+#version 460 core
|
||||
|
||||
//============================================================================================================
|
||||
//
|
||||
@@ -25,7 +25,7 @@ precision highp int;
|
||||
|
||||
#define EdgeThreshold 8.0/255.0
|
||||
|
||||
-#define EdgeSharpness 2.0
|
||||
+// #define EdgeSharpness 2.0
|
||||
|
||||
// #define UseUniformBlock
|
||||
|
||||
@@ -34,17 +34,18 @@ precision highp int;
|
||||
////////////////////////
|
||||
|
||||
#if defined(UseUniformBlock)
|
||||
-layout (set=0, binding = 0) uniform UniformBlock
|
||||
-{
|
||||
- highp vec4 ViewportInfo[1];
|
||||
+layout( push_constant ) uniform constants {
|
||||
+ highp vec4 ViewportInfo[1];
|
||||
+ highp vec2 ResizeFactor;
|
||||
+ highp float EdgeSharpness;
|
||||
};
|
||||
-layout(set = 0, binding = 1) uniform mediump sampler2D ps0;
|
||||
+layout(set = 0, binding = 0) uniform mediump sampler2D ps0;
|
||||
#else
|
||||
uniform highp vec4 ViewportInfo[1];
|
||||
uniform mediump sampler2D ps0;
|
||||
#endif
|
||||
|
||||
-layout(location=0) in highp vec4 in_TEXCOORD0;
|
||||
+layout(location=0) in highp vec2 in_TEXCOORD0;
|
||||
layout(location=0) out vec4 out_Target0;
|
||||
|
||||
float fastLanczos2(float x)
|
||||
@@ -63,15 +64,11 @@ vec2 weightY(float dx, float dy,float c, float std)
|
||||
|
||||
void main()
|
||||
{
|
||||
- int mode = OperationMode;
|
||||
- float edgeThreshold = EdgeThreshold;
|
||||
- float edgeSharpness = EdgeSharpness;
|
||||
-
|
||||
vec4 color;
|
||||
- if(mode == 1)
|
||||
- color.xyz = textureLod(ps0,in_TEXCOORD0.xy,0.0).xyz;
|
||||
+ if(OperationMode == 1)
|
||||
+ color.xyz = textureLod(ps0, in_TEXCOORD0.xy, 0.0).xyz;
|
||||
else
|
||||
- color.xyzw = textureLod(ps0,in_TEXCOORD0.xy,0.0).xyzw;
|
||||
+ color.xyzw = textureLod(ps0, in_TEXCOORD0.xy, 0.0).xyzw;
|
||||
|
||||
highp float xCenter;
|
||||
xCenter = abs(in_TEXCOORD0.x+-0.5);
|
||||
@@ -79,30 +76,33 @@ void main()
|
||||
yCenter = abs(in_TEXCOORD0.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)
|
||||
+ //if ( OperationMode!=4 && xCenter*xCenter+yCenter*yCenter<=0.4 * 0.4)
|
||||
+ if ( OperationMode!=4)
|
||||
{
|
||||
- highp vec2 imgCoord = ((in_TEXCOORD0.xy*ViewportInfo[0].zw)+vec2(-0.5,0.5));
|
||||
+ highp vec2 imgCoord = ((in_TEXCOORD0.xy * ViewportInfo[0].zw) + vec2(-0.5,0.5));
|
||||
highp vec2 imgCoordPixel = floor(imgCoord);
|
||||
- highp vec2 coord = (imgCoordPixel*ViewportInfo[0].xy);
|
||||
- vec2 pl = (imgCoord+(-imgCoordPixel));
|
||||
- vec4 left = textureGather(ps0,coord, mode);
|
||||
+ highp vec2 coord = imgCoordPixel * ViewportInfo[0].xy;
|
||||
+ vec2 pl = imgCoord - imgCoordPixel;
|
||||
+ vec4 left = textureGather(ps0, coord, OperationMode);
|
||||
|
||||
- float edgeVote = abs(left.z - left.y) + abs(color[mode] - left.y) + abs(color[mode] - left.z) ;
|
||||
- if(edgeVote > edgeThreshold)
|
||||
+ float edgeVote = abs(left.z - left.y) + abs(color[OperationMode] - left.y) + abs(color[OperationMode] - left.z) ;
|
||||
+ if(edgeVote > EdgeThreshold)
|
||||
{
|
||||
coord.x += ViewportInfo[0].x;
|
||||
|
||||
- vec4 right = textureGather(ps0,coord + highp vec2(ViewportInfo[0].x, 0.0), mode);
|
||||
+ highp vec2 IR_highp_vec2_0 = coord + vec2(ViewportInfo[0].x, 0.0);
|
||||
+ vec4 right = textureGather(ps0, IR_highp_vec2_0, OperationMode);
|
||||
vec4 upDown;
|
||||
- upDown.xy = textureGather(ps0,coord + highp vec2(0.0, -ViewportInfo[0].y),mode).wz;
|
||||
- upDown.zw = textureGather(ps0,coord+ highp vec2(0.0, ViewportInfo[0].y), mode).yx;
|
||||
+ highp vec2 IR_highp_vec2_1 = coord + vec2(0.0, -ViewportInfo[0].y);
|
||||
+ upDown.xy = textureGather(ps0, IR_highp_vec2_1, OperationMode).wz;
|
||||
+ highp vec2 IR_highp_vec2_2 = coord + vec2(0.0, ViewportInfo[0].y);
|
||||
+ upDown.zw = textureGather(ps0, IR_highp_vec2_2, OperationMode).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;
|
||||
+ color.w =color[OperationMode] - 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;
|
||||
@@ -124,7 +124,7 @@ void main()
|
||||
|
||||
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);
|
||||
+ finalY = clamp(EdgeSharpness*finalY, minY, maxY);
|
||||
|
||||
float deltaY = finalY -color.w;
|
||||
|
||||
diff --git a/sgsr/v1/include/glsl/sgsr1_shader_mobile_edge_direction.frag b/sgsr/v1/include/glsl/sgsr1_shader_mobile_edge_direction.frag
|
||||
index d2df646..5a38589 100644
|
||||
--- a/sgsr/v1/include/glsl/sgsr1_shader_mobile_edge_direction.frag
|
||||
+++ b/sgsr/v1/include/glsl/sgsr1_shader_mobile_edge_direction.frag
|
||||
@@ -1,4 +1,4 @@
|
||||
-#version 300 es
|
||||
+#version 460 core
|
||||
|
||||
//============================================================================================================
|
||||
//
|
||||
@@ -27,11 +27,11 @@ precision highp int;
|
||||
* If set, will use edge direction to improve visual quality
|
||||
* Expect a minimal cost increase
|
||||
*/
|
||||
-// #define UseEdgeDirection
|
||||
+#define UseEdgeDirection 1
|
||||
|
||||
#define EdgeThreshold 8.0/255.0
|
||||
|
||||
-#define EdgeSharpness 2.0
|
||||
+// #define EdgeSharpness 2.0
|
||||
|
||||
// #define UseUniformBlock
|
||||
|
||||
@@ -40,17 +40,18 @@ precision highp int;
|
||||
////////////////////////
|
||||
|
||||
#if defined(UseUniformBlock)
|
||||
-layout (set=0, binding = 0) uniform UniformBlock
|
||||
-{
|
||||
- highp vec4 ViewportInfo[1];
|
||||
+layout( push_constant ) uniform constants {
|
||||
+ highp vec4 ViewportInfo[1];
|
||||
+ highp vec2 ResizeFactor;
|
||||
+ highp float EdgeSharpness;
|
||||
};
|
||||
-layout(set = 0, binding = 1) uniform mediump sampler2D ps0;
|
||||
+layout(set = 0, binding = 0) uniform mediump sampler2D ps0;
|
||||
#else
|
||||
uniform highp vec4 ViewportInfo[1];
|
||||
uniform mediump sampler2D ps0;
|
||||
#endif
|
||||
|
||||
-layout(location=0) in highp vec4 in_TEXCOORD0;
|
||||
+layout(location=0) in highp vec2 in_TEXCOORD0;
|
||||
layout(location=0) out vec4 out_Target0;
|
||||
|
||||
float fastLanczos2(float x)
|
||||
@@ -116,18 +117,21 @@ void main()
|
||||
highp vec2 imgCoord = ((in_TEXCOORD0.xy*ViewportInfo[0].zw)+vec2(-0.5,0.5));
|
||||
highp vec2 imgCoordPixel = floor(imgCoord);
|
||||
highp vec2 coord = (imgCoordPixel*ViewportInfo[0].xy);
|
||||
- vec2 pl = (imgCoord+(-imgCoordPixel));
|
||||
- vec4 left = textureGather(ps0,coord, OperationMode);
|
||||
+ vec2 pl = imgCoord - imgCoordPixel;
|
||||
+ vec4 left = textureGather(ps0, coord, OperationMode);
|
||||
|
||||
float edgeVote = abs(left.z - left.y) + abs(color[OperationMode] - left.y) + abs(color[OperationMode] - left.z) ;
|
||||
if(edgeVote > EdgeThreshold)
|
||||
{
|
||||
coord.x += ViewportInfo[0].x;
|
||||
|
||||
- vec4 right = textureGather(ps0,coord + highp vec2(ViewportInfo[0].x, 0.0), OperationMode);
|
||||
+ highp vec2 IR_highp_vec2_0 = coord + vec2(ViewportInfo[0].x, 0.0);
|
||||
+ vec4 right = textureGather(ps0, IR_highp_vec2_0, OperationMode);
|
||||
vec4 upDown;
|
||||
- upDown.xy = textureGather(ps0,coord + highp vec2(0.0, -ViewportInfo[0].y),OperationMode).wz;
|
||||
- upDown.zw = textureGather(ps0,coord+ highp vec2(0.0, ViewportInfo[0].y), OperationMode).yx;
|
||||
+ highp vec2 IR_highp_vec2_1 = coord + vec2(0.0, -ViewportInfo[0].y);
|
||||
+ upDown.xy = textureGather(ps0, IR_highp_vec2_1, OperationMode).wz;
|
||||
+ highp vec2 IR_highp_vec2_2 = coord + vec2(0.0, ViewportInfo[0].y);
|
||||
+ upDown.zw = textureGather(ps0, IR_highp_vec2_2, OperationMode).yx;
|
||||
|
||||
float mean = (left.y+left.z+right.x+right.w)*0.25;
|
||||
left = left - vec4(mean);
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
diff --git a/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag b/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
|
||||
index 2db04b3..056d177 100644
|
||||
--- a/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
|
||||
+++ b/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
|
||||
@@ -8,8 +8,10 @@
|
||||
//
|
||||
//============================================================================================================
|
||||
|
||||
-precision mediump float;
|
||||
-precision highp int;
|
||||
+//precision mediump float;
|
||||
+//precision highp int;
|
||||
+#define highp
|
||||
+#define mediump
|
||||
|
||||
////////////////////////
|
||||
// USER CONFIGURATION //
|
||||
diff --git a/sgsr/v1/include/glsl/sgsr1_shader_mobile_edge_direction.frag b/sgsr/v1/include/glsl/sgsr1_shader_mobile_edge_direction.frag
|
||||
index 5a38589..5ed5f5e 100644
|
||||
--- a/sgsr/v1/include/glsl/sgsr1_shader_mobile_edge_direction.frag
|
||||
+++ b/sgsr/v1/include/glsl/sgsr1_shader_mobile_edge_direction.frag
|
||||
@@ -8,8 +8,10 @@
|
||||
//
|
||||
//============================================================================================================
|
||||
|
||||
-precision mediump float;
|
||||
-precision highp int;
|
||||
+//precision mediump float;
|
||||
+//precision highp int;
|
||||
+#define highp
|
||||
+#define mediump
|
||||
|
||||
////////////////////////
|
||||
// USER CONFIGURATION //
|
||||
|
|
@ -233,8 +233,6 @@ endif()
|
|||
|
||||
option(YUZU_USE_BUNDLED_OPENSSL "Download bundled OpenSSL build" ${DEFAULT_YUZU_USE_BUNDLED_OPENSSL})
|
||||
|
||||
AddJsonPackage(sgsr)
|
||||
|
||||
# TODO(crueter): CPM this
|
||||
if (ANDROID AND YUZU_DOWNLOAD_ANDROID_VVL)
|
||||
AddJsonPackage(vulkan-validation-layers)
|
||||
|
|
|
|||
|
|
@ -102,15 +102,6 @@
|
|||
"artifact": "android-binaries-%VERSION%.zip",
|
||||
"hash": "8812ae84cbe49e6a3418ade9c458d3be6d74a3dffd319d4502007b564d580998056e8190414368ec11b27bc83993c7a0dad713c31bcc3d9553b51243efee3753"
|
||||
},
|
||||
"sgsr": {
|
||||
"repo": "SnapdragonStudios/snapdragon-gsr",
|
||||
"hash": "3940df715189813ffeffa540f48673e999754d53a1dcadc16aab846ef03d57e395e2c8d8e89772bc162835e1686ff6bdb8cae108c1f84404e9e66d993107b76e",
|
||||
"sha": "d926f074bcb9d714e179f1ce0fcb9ee2eeb5074e",
|
||||
"patches": [
|
||||
"0001-fix-glsl.patch",
|
||||
"0002-remove-highp.patch"
|
||||
]
|
||||
},
|
||||
"quazip": {
|
||||
"package": "QuaZip-Qt6",
|
||||
"repo": "stachenov/quazip",
|
||||
|
|
|
|||
|
|
@ -79,8 +79,8 @@ set(SHADER_FILES
|
|||
|
||||
# Snapdragon Game Super Resolution
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sgsr1_shader.vert
|
||||
${sgsr_SOURCE_DIR}/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
|
||||
${sgsr_SOURCE_DIR}/sgsr/v1/include/glsl/sgsr1_shader_mobile_edge_direction.frag
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sgsr1_shader_mobile.frag
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sgsr1_shader_mobile_edge_direction.frag
|
||||
)
|
||||
|
||||
if (PLATFORM_HAIKU)
|
||||
|
|
@ -192,4 +192,3 @@ add_custom_target(host_shaders
|
|||
SOURCES
|
||||
${SHADER_SOURCES}
|
||||
)
|
||||
#add_dependencies(host_shaders sgsr::sgsr)
|
||||
|
|
|
|||
116
src/video_core/host_shaders/sgsr1_shader_mobile.frag
Normal file
116
src/video_core/host_shaders/sgsr1_shader_mobile.frag
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
// SPDX-FileCopyrightText: Copyright (c) 2025, Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#version 460 core
|
||||
|
||||
//precision mediump float;
|
||||
//precision highp int;
|
||||
#define highp
|
||||
#define mediump
|
||||
|
||||
// Operation modes: RGBA -> 1, RGBY -> 3, LERP -> 4
|
||||
#define OperationMode 1
|
||||
#define EdgeThreshold 8.0/255.0
|
||||
// #define EdgeSharpness 2.0
|
||||
// #define UseUniformBlock
|
||||
|
||||
#if defined(UseUniformBlock)
|
||||
layout( push_constant ) uniform constants {
|
||||
highp vec4 ViewportInfo[1];
|
||||
highp vec2 ResizeFactor;
|
||||
highp float EdgeSharpness;
|
||||
};
|
||||
layout(set = 0, binding = 0) uniform mediump sampler2D ps0;
|
||||
#else
|
||||
uniform highp vec4 ViewportInfo[1];
|
||||
uniform mediump sampler2D ps0;
|
||||
#endif
|
||||
|
||||
layout(location=0) in highp vec2 in_TEXCOORD0;
|
||||
layout(location=0) out vec4 out_Target0;
|
||||
|
||||
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() {
|
||||
vec4 color;
|
||||
if(OperationMode == 1)
|
||||
color.xyz = textureLod(ps0, in_TEXCOORD0.xy, 0.0).xyz;
|
||||
else
|
||||
color.xyzw = textureLod(ps0, in_TEXCOORD0.xy, 0.0).xyzw;
|
||||
|
||||
highp float xCenter = abs(in_TEXCOORD0.x + -0.5);
|
||||
highp float yCenter = abs(in_TEXCOORD0.y + -0.5);
|
||||
|
||||
//todo: config the SR region based on needs
|
||||
//if ( OperationMode!=4 && xCenter*xCenter+yCenter*yCenter<=0.4 * 0.4)
|
||||
if ( OperationMode!=4) {
|
||||
highp vec2 imgCoord = ((in_TEXCOORD0.xy * ViewportInfo[0].zw) + vec2(-0.5, 0.5));
|
||||
highp vec2 imgCoordPixel = floor(imgCoord);
|
||||
highp vec2 coord = imgCoordPixel * ViewportInfo[0].xy;
|
||||
vec2 pl = imgCoord - imgCoordPixel;
|
||||
vec4 left = textureGather(ps0, coord, OperationMode);
|
||||
float edgeVote = abs(left.z - left.y) + abs(color[OperationMode] - left.y) + abs(color[OperationMode] - left.z) ;
|
||||
if(edgeVote > EdgeThreshold) {
|
||||
coord.x += ViewportInfo[0].x;
|
||||
|
||||
highp vec2 IR_highp_vec2_0 = coord + vec2(ViewportInfo[0].x, 0.0);
|
||||
vec4 right = textureGather(ps0, IR_highp_vec2_0, OperationMode);
|
||||
vec4 upDown;
|
||||
highp vec2 IR_highp_vec2_1 = coord + vec2(0.0, -ViewportInfo[0].y);
|
||||
upDown.xy = textureGather(ps0, IR_highp_vec2_1, OperationMode).wz;
|
||||
highp vec2 IR_highp_vec2_2 = coord + vec2(0.0, ViewportInfo[0].y);
|
||||
upDown.zw = textureGather(ps0, IR_highp_vec2_2, OperationMode).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[OperationMode] - 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
|
||||
out_Target0.xyzw = color;
|
||||
}
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
// SPDX-FileCopyrightText: Copyright (c) 2025, Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#version 460 core
|
||||
|
||||
//precision mediump float;
|
||||
//precision highp int;
|
||||
#define highp
|
||||
#define mediump
|
||||
|
||||
// Operation modes: RGBA -> 1, RGBY -> 3, LERP -> 4
|
||||
#define OperationMode 1
|
||||
// If set, will use edge direction to improve visual quality
|
||||
// Expect a minimal cost increase
|
||||
#define UseEdgeDirection 1
|
||||
#define EdgeThreshold 8.0/255.0
|
||||
// #define EdgeSharpness 2.0
|
||||
// #define UseUniformBlock
|
||||
|
||||
#if defined(UseUniformBlock)
|
||||
layout( push_constant ) uniform constants {
|
||||
highp vec4 ViewportInfo[1];
|
||||
highp vec2 ResizeFactor;
|
||||
highp float EdgeSharpness;
|
||||
};
|
||||
layout(set = 0, binding = 0) uniform mediump sampler2D ps0;
|
||||
#else
|
||||
uniform highp vec4 ViewportInfo[1];
|
||||
uniform mediump sampler2D ps0;
|
||||
#endif
|
||||
|
||||
layout(location=0) in highp vec2 in_TEXCOORD0;
|
||||
layout(location=0) out vec4 out_Target0;
|
||||
|
||||
float fastLanczos2(float x) {
|
||||
float wA = x-4.0;
|
||||
float wB = x*wA-wA;
|
||||
wA *= wA;
|
||||
return wB*wA;
|
||||
}
|
||||
|
||||
#if defined(UseEdgeDirection)
|
||||
vec2 weightY(float dx, float dy, float c, vec3 data)
|
||||
#else
|
||||
vec2 weightY(float dx, float dy, float c, float data)
|
||||
#endif
|
||||
{
|
||||
#if defined(UseEdgeDirection)
|
||||
float std = data.x;
|
||||
vec2 dir = data.yz;
|
||||
|
||||
float edgeDis = ((dx*dir.y)+(dy*dir.x));
|
||||
float x = (((dx*dx)+(dy*dy))+((edgeDis*edgeDis)*((clamp(((c*c)*std),0.0,1.0)*0.7)+-1.0)));
|
||||
#else
|
||||
float std = data;
|
||||
float x = ((dx*dx)+(dy* dy))* 0.55 + clamp(abs(c)*std, 0.0, 1.0);
|
||||
#endif
|
||||
|
||||
float w = fastLanczos2(x);
|
||||
return vec2(w, w * c);
|
||||
}
|
||||
|
||||
vec2 edgeDirection(vec4 left, vec4 right) {
|
||||
vec2 dir;
|
||||
float RxLz = (right.x + (-left.z));
|
||||
float RwLy = (right.w + (-left.y));
|
||||
vec2 delta;
|
||||
delta.x = (RxLz + RwLy);
|
||||
delta.y = (RxLz + (-RwLy));
|
||||
float lengthInv = inversesqrt((delta.x * delta.x+ 3.075740e-05) + (delta.y * delta.y));
|
||||
dir.x = (delta.x * lengthInv);
|
||||
dir.y = (delta.y * lengthInv);
|
||||
return dir;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 color;
|
||||
if(OperationMode == 1)
|
||||
color.xyz = textureLod(ps0, in_TEXCOORD0.xy, 0.0).xyz;
|
||||
else
|
||||
color.xyzw = textureLod(ps0, in_TEXCOORD0.xy, 0.0).xyzw;
|
||||
|
||||
highp float xCenter = abs(in_TEXCOORD0.x + -0.5);
|
||||
highp float yCenter = abs(in_TEXCOORD0.y + -0.5);
|
||||
|
||||
//todo: config the SR region based on needs
|
||||
//if ( OperationMode!=4 && xCenter*xCenter+yCenter*yCenter<=0.4 * 0.4)
|
||||
if ( OperationMode!=4) {
|
||||
highp vec2 imgCoord = ((in_TEXCOORD0.xy*ViewportInfo[0].zw)+vec2(-0.5,0.5));
|
||||
highp vec2 imgCoordPixel = floor(imgCoord);
|
||||
highp vec2 coord = (imgCoordPixel*ViewportInfo[0].xy);
|
||||
vec2 pl = imgCoord - imgCoordPixel;
|
||||
vec4 left = textureGather(ps0, coord, OperationMode);
|
||||
float edgeVote = abs(left.z - left.y) + abs(color[OperationMode] - left.y) + abs(color[OperationMode] - left.z) ;
|
||||
if(edgeVote > EdgeThreshold) {
|
||||
coord.x += ViewportInfo[0].x;
|
||||
|
||||
highp vec2 IR_highp_vec2_0 = coord + vec2(ViewportInfo[0].x, 0.0);
|
||||
vec4 right = textureGather(ps0, IR_highp_vec2_0, OperationMode);
|
||||
vec4 upDown;
|
||||
highp vec2 IR_highp_vec2_1 = coord + vec2(0.0, -ViewportInfo[0].y);
|
||||
upDown.xy = textureGather(ps0, IR_highp_vec2_1, OperationMode).wz;
|
||||
highp vec2 IR_highp_vec2_2 = coord + vec2(0.0, ViewportInfo[0].y);
|
||||
upDown.zw = textureGather(ps0, IR_highp_vec2_2, OperationMode).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[OperationMode] - 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 sumMean = 1.014185e+01/sum;
|
||||
float std = (sumMean*sumMean);
|
||||
|
||||
#if defined(UseEdgeDirection)
|
||||
vec3 data = vec3(std, edgeDirection(left, right));
|
||||
#else
|
||||
float data = std;
|
||||
#endif
|
||||
vec2 aWY = weightY(pl.x, pl.y+1.0, upDown.x,data);
|
||||
aWY += weightY(pl.x-1.0, pl.y+1.0, upDown.y,data);
|
||||
aWY += weightY(pl.x-1.0, pl.y-2.0, upDown.z,data);
|
||||
aWY += weightY(pl.x, pl.y-2.0, upDown.w,data);
|
||||
aWY += weightY(pl.x+1.0, pl.y-1.0, left.x,data);
|
||||
aWY += weightY(pl.x, pl.y-1.0, left.y,data);
|
||||
aWY += weightY(pl.x, pl.y, left.z,data);
|
||||
aWY += weightY(pl.x+1.0, pl.y, left.w,data);
|
||||
aWY += weightY(pl.x-1.0, pl.y-1.0, right.x,data);
|
||||
aWY += weightY(pl.x-2.0, pl.y-1.0, right.y,data);
|
||||
aWY += weightY(pl.x-2.0, pl.y, right.z,data);
|
||||
aWY += weightY(pl.x-1.0, pl.y, right.w,data);
|
||||
|
||||
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));
|
||||
float deltaY = clamp(EdgeSharpness*finalY, minY, maxY) -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
|
||||
out_Target0.xyzw = color;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue