mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-02-04 02:51:18 +01:00
allow control sharpness from [0,2.0]
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
diff --git a/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag b/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
|
||||
index 7074999..c23aae4 100644
|
||||
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 @@
|
||||
@@ -8,7 +8,16 @@ index 7074999..c23aae4 100644
|
||||
|
||||
//============================================================================================================
|
||||
//
|
||||
@@ -34,17 +34,17 @@ precision highp int;
|
||||
@@ -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)
|
||||
@@ -18,6 +27,7 @@ index 7074999..c23aae4 100644
|
||||
+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;
|
||||
@@ -31,20 +41,18 @@ index 7074999..c23aae4 100644
|
||||
layout(location=0) out vec4 out_Target0;
|
||||
|
||||
float fastLanczos2(float x)
|
||||
@@ -63,15 +63,15 @@ vec2 weightY(float dx, float dy,float c, float std)
|
||||
@@ -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;
|
||||
+ const int mode = OperationMode;
|
||||
+ const float edgeThreshold = EdgeThreshold;
|
||||
+ const float edgeSharpness = EdgeSharpness;
|
||||
|
||||
-
|
||||
vec4 color;
|
||||
if(mode == 1)
|
||||
- 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;
|
||||
@@ -52,9 +60,14 @@ index 7074999..c23aae4 100644
|
||||
|
||||
highp float xCenter;
|
||||
xCenter = abs(in_TEXCOORD0.x+-0.5);
|
||||
@@ -82,21 +82,24 @@ void main()
|
||||
//if ( mode!=4 && xCenter*xCenter+yCenter*yCenter<=0.4 * 0.4)
|
||||
if ( mode!=4)
|
||||
@@ -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));
|
||||
@@ -64,28 +77,46 @@ index 7074999..c23aae4 100644
|
||||
- vec4 left = textureGather(ps0,coord, mode);
|
||||
+ highp vec2 coord = imgCoordPixel * ViewportInfo[0].xy;
|
||||
+ vec2 pl = imgCoord - imgCoordPixel;
|
||||
+ vec4 left = textureGather(ps0, coord, mode);
|
||||
+ 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[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, mode);
|
||||
+ 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, mode).wz;
|
||||
+ 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, mode).yx;
|
||||
+ 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..8b64497 100644
|
||||
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 @@
|
||||
@@ -94,7 +125,21 @@ index d2df646..8b64497 100644
|
||||
|
||||
//============================================================================================================
|
||||
//
|
||||
@@ -40,17 +40,17 @@ precision highp int;
|
||||
@@ -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)
|
||||
@@ -104,6 +149,7 @@ index d2df646..8b64497 100644
|
||||
+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;
|
||||
@@ -117,7 +163,7 @@ index d2df646..8b64497 100644
|
||||
layout(location=0) out vec4 out_Target0;
|
||||
|
||||
float fastLanczos2(float x)
|
||||
@@ -116,18 +116,21 @@ void main()
|
||||
@@ -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);
|
||||
|
||||
@@ -463,8 +463,8 @@
|
||||
<string name="renderer_resolution">Resolution (Handheld/Docked)</string>
|
||||
<string name="renderer_vsync">VSync mode</string>
|
||||
<string name="renderer_scaling_filter">Window adapting filter</string>
|
||||
<string name="fsr_sharpness">FSR sharpness</string>
|
||||
<string name="fsr_sharpness_description">Determines how sharpened the image will look while using FSR\'s dynamic contrast</string>
|
||||
<string name="fsr_sharpness">FSR/SGSR sharpness</string>
|
||||
<string name="fsr_sharpness_description">Determines how sharpened the image will look while using FSR or SGSR filters</string>
|
||||
<string name="renderer_anti_aliasing">Anti-aliasing method</string>
|
||||
<string name="renderer_optimize_spirv_output">Optimize SPIRV output</string>
|
||||
<string name="renderer_optimize_spirv_output_description">Optimizes compiled shaders to improve GPU efficiency, but may introduce longer loading times and initial slowdowns.</string>
|
||||
|
||||
@@ -172,8 +172,8 @@ std::unique_ptr<TranslationMap> InitializeTranslations(QObject* parent)
|
||||
INSERT(Settings, scaling_filter, tr("Window Adapting Filter:"), QString());
|
||||
INSERT(Settings,
|
||||
fsr_sharpening_slider,
|
||||
tr("FSR Sharpness:"),
|
||||
tr("Determines how sharpened the image will look using FSR's dynamic contrast."));
|
||||
tr("FSR/SGSR Sharpness:"),
|
||||
tr("Determines how sharpened the image will look using FSR or SGSR filters."));
|
||||
INSERT(Settings,
|
||||
anti_aliasing,
|
||||
tr("Anti-Aliasing Method:"),
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
layout( push_constant ) uniform constants {
|
||||
highp vec4 ViewportInfo[1];
|
||||
highp vec2 ResizeFactor;
|
||||
highp float EdgeSharpness;
|
||||
};
|
||||
layout(location = 0) out highp vec2 texcoord;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
namespace Vulkan {
|
||||
|
||||
using PushConstants = std::array<u32, 4 + 2>;
|
||||
using PushConstants = std::array<u32, 4 + 2 + 1>;
|
||||
|
||||
SGSR::SGSR(const Device& device, MemoryAllocator& memory_allocator, size_t image_count, VkExtent2D extent, bool edge_dir)
|
||||
: m_device{device}, m_memory_allocator{memory_allocator}
|
||||
@@ -102,9 +102,16 @@ VkImageView SGSR::Draw(Scheduler& scheduler, size_t image_index, VkImage source_
|
||||
const f32 input_image_height = f32(input_image_extent.height);
|
||||
const f32 viewport_width = (crop_rect.right - crop_rect.left) * input_image_width;
|
||||
const f32 viewport_height = (crop_rect.bottom - crop_rect.top) * input_image_height;
|
||||
// expected [0, 2]
|
||||
const f32 sharpening = f32(Settings::values.fsr_sharpening_slider.GetValue()) / 100.0f;
|
||||
|
||||
// p = (tex * viewport) / input = [0,n] (normalized texcoords)
|
||||
// p * input = [0,1024], [0,768]
|
||||
// layout( push_constant ) uniform constants {
|
||||
// highp vec4 ViewportInfo[1];
|
||||
// highp vec2 ResizeFactor;
|
||||
// highp float EdgeSharpness;
|
||||
// };
|
||||
PushConstants viewport_con{};
|
||||
viewport_con[0] = std::bit_cast<u32>(1.f / viewport_width);
|
||||
viewport_con[1] = std::bit_cast<u32>(1.f / viewport_height);
|
||||
@@ -112,6 +119,7 @@ VkImageView SGSR::Draw(Scheduler& scheduler, size_t image_index, VkImage source_
|
||||
viewport_con[3] = std::bit_cast<u32>(viewport_height);
|
||||
viewport_con[4] = std::bit_cast<u32>(viewport_width / input_image_width);
|
||||
viewport_con[5] = std::bit_cast<u32>(viewport_height / input_image_height);
|
||||
viewport_con[6] = std::bit_cast<u32>(sharpening);
|
||||
|
||||
UploadImages(scheduler);
|
||||
UpdateDescriptorSets(source_image_view, image_index);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
|
||||
@@ -266,7 +266,7 @@ void ConfigureGraphics::Setup(const ConfigurationShared::Builder& builder) {
|
||||
// FSR needs a reversed slider and a 0.5 multiplier
|
||||
return builder.BuildWidget(
|
||||
setting, apply_funcs, ConfigurationShared::RequestType::ReverseSlider, true,
|
||||
0.5f, nullptr, tr("%", "FSR sharpening percentage (e.g. 50%)"));
|
||||
0.5f, nullptr, tr("%", "FSR/SGSR sharpening percentage (e.g. 50%)"));
|
||||
} else {
|
||||
return builder.BuildWidget(setting, apply_funcs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user