mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-09-08 13:11:02 +00:00
What if we just rely entirely on SGSR common than using EdgeDir?
This commit is contained in:
@@ -6,9 +6,9 @@
|
|||||||
precision highp float;
|
precision highp float;
|
||||||
precision highp int;
|
precision highp int;
|
||||||
|
|
||||||
// Operation modes: RGBA -> 1, RGBY -> 3, LERP -> 4
|
|
||||||
#define OPERATION_MODE 1
|
|
||||||
#define EDGE_THRESHOLD (8.0 / 255.0)
|
#define EDGE_THRESHOLD (8.0 / 255.0)
|
||||||
|
#define DIRECTION_EPSILON 6.5e-05
|
||||||
|
#define DEVIATION_FLOOR 6.0e-02
|
||||||
|
|
||||||
layout(push_constant) uniform constants {
|
layout(push_constant) uniform constants {
|
||||||
vec2 scale;
|
vec2 scale;
|
||||||
@@ -21,20 +21,37 @@ layout(set = 0, binding = 0) uniform sampler2D sampler0;
|
|||||||
layout(location=0) in vec2 texcoord;
|
layout(location=0) in vec2 texcoord;
|
||||||
layout(location=0) out vec4 frag_color;
|
layout(location=0) out vec4 frag_color;
|
||||||
|
|
||||||
vec4 weightY(vec4 dx, vec4 dy, vec4 std) {
|
mediump vec4 fastLanczos2(mediump vec4 x) {
|
||||||
vec4 x = ((dx * dx) + (dy * dy)) * 0.55f + std;
|
mediump vec4 wA = x - 4.0f;
|
||||||
return (x - 1.f) * (x - 4.f) * 3.8125f; // approx. of (x - 1) * (x - 4)^3
|
mediump vec4 wB = x * wA - wA;
|
||||||
|
wA *= wA;
|
||||||
|
return wB * wA;
|
||||||
|
}
|
||||||
|
|
||||||
|
mediump vec2 edgeDirection(mediump vec4 left, mediump vec4 right) {
|
||||||
|
mediump float RxLz = right.x - left.z;
|
||||||
|
mediump float RwLy = right.w - left.y;
|
||||||
|
mediump vec2 delta = vec2(RxLz + RwLy, RxLz - RwLy);
|
||||||
|
mediump float length_inv =
|
||||||
|
inversesqrt((delta.x * delta.x + DIRECTION_EPSILON) + delta.y * delta.y);
|
||||||
|
return delta * length_inv;
|
||||||
|
}
|
||||||
|
|
||||||
|
mediump vec4 weightY(mediump vec4 dx, mediump vec4 dy, mediump vec4 c, mediump float std,
|
||||||
|
mediump vec2 dir) {
|
||||||
|
mediump vec4 edge_dis = dx * dir.y + dy * dir.x;
|
||||||
|
mediump vec4 x = (dx * dx + dy * dy) +
|
||||||
|
(edge_dis * edge_dis) * (clamp((c * c) * std, 0.0f, 1.0f) * 0.7f - 1.0f);
|
||||||
|
return fastLanczos2(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 color = textureLod(sampler0, texcoord.xy, 0.0f);
|
mediump vec4 color = textureLod(sampler0, texcoord.xy, 0.0f);
|
||||||
// image coord
|
highp vec2 icoord = (texcoord * size + vec2(-0.5f, 0.5f));
|
||||||
vec2 icoord = (texcoord * size + vec2(-0.5f, 0.5f));
|
highp vec2 icoord_pixel = floor(icoord);
|
||||||
vec2 icoord_pixel = floor(icoord);
|
highp vec2 coord = icoord_pixel * scale;
|
||||||
vec2 coord = icoord_pixel * scale;
|
mediump vec2 pl = icoord - icoord_pixel;
|
||||||
vec2 pl = icoord - icoord_pixel;
|
mediump mat3x4 dg = mat3x4(
|
||||||
// left: 0, right: 1, upDown: 2
|
|
||||||
mat3x4 dg = mat3x4(
|
|
||||||
textureGather(sampler0, coord, 1),
|
textureGather(sampler0, coord, 1),
|
||||||
textureGather(sampler0, coord + vec2(2.f * scale.x, 0.0f), 1),
|
textureGather(sampler0, coord + vec2(2.f * scale.x, 0.0f), 1),
|
||||||
vec4(
|
vec4(
|
||||||
@@ -42,42 +59,40 @@ void main() {
|
|||||||
textureGather(sampler0, coord + vec2(scale.x, +scale.y), 1).yx
|
textureGather(sampler0, coord + vec2(scale.x, +scale.y), 1).yx
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
float edgeVote = abs(dg[0].z - dg[0].y) + abs(color.y - dg[0].y) + abs(color.y - dg[0].z);
|
mediump float edgeVote =
|
||||||
|
abs(dg[0].z - dg[0].y) + abs(color.y - dg[0].y) + abs(color.y - dg[0].z);
|
||||||
if (edgeVote > EDGE_THRESHOLD) {
|
if (edgeVote > EDGE_THRESHOLD) {
|
||||||
float mean = (dg[0].y + dg[0].z + dg[1].x + dg[1].w) * 0.25f;
|
mediump float mean = (dg[0].y + dg[0].z + dg[1].x + dg[1].w) * 0.25f;
|
||||||
dg = dg - mean;
|
dg = dg - mean;
|
||||||
vec4 sum = abs(dg[0]) + abs(dg[1]) + abs(dg[2]);
|
mediump float sum = dot(abs(dg[0]) + abs(dg[1]) + abs(dg[2]), vec4(1.0f));
|
||||||
float std = 2.181818f / (sum.x + sum.y + sum.z + sum.w);
|
mediump float sum_mean = 1.014185e+01f / max(sum, DEVIATION_FLOOR);
|
||||||
mat2x4 w = mat2x4(
|
mediump float std = sum_mean * sum_mean;
|
||||||
weightY(
|
mediump vec2 dir = edgeDirection(dg[0], dg[1]);
|
||||||
pl.xxxx + vec4(+1.0f, +0.0f, +0.0f, +1.0f),
|
mediump vec4 w0 = weightY(
|
||||||
pl.yyyy + vec4(-1.0f, -1.0f, +0.0f, +0.0f),
|
pl.xxxx + vec4(+1.0f, +0.0f, +0.0f, +1.0f),
|
||||||
clamp(abs(dg[0]) * std, 0.0f, 1.0f)
|
pl.yyyy + vec4(-1.0f, -1.0f, +0.0f, +0.0f),
|
||||||
) + weightY(
|
dg[0], std, dir
|
||||||
pl.xxxx + vec4(-1.0f, -2.0f, -2.0f, -1.0f),
|
|
||||||
pl.yyyy + vec4(-1.0f, -1.0f, +0.0f, +0.0f),
|
|
||||||
clamp(abs(dg[1]) * std, 0.0f, 1.0f)
|
|
||||||
) + weightY(
|
|
||||||
pl.xxxx + vec4(+0.0f, -1.0f, -1.0f, +0.0f),
|
|
||||||
pl.yyyy + vec4(+1.0f, +1.0f, -2.0f, -2.0f),
|
|
||||||
clamp(abs(dg[2]) * std, 0.0f, 1.0f)
|
|
||||||
),
|
|
||||||
dg[0] + dg[1] + dg[2]
|
|
||||||
);
|
);
|
||||||
// compute final y with bounds
|
mediump vec4 w1 = weightY(
|
||||||
vec2 yb = vec2(
|
pl.xxxx + vec4(-1.0f, -2.0f, -2.0f, -1.0f),
|
||||||
min(min(dg[0].y, dg[0].z), min(dg[1].x, dg[1].w)), // min
|
pl.yyyy + vec4(-1.0f, -1.0f, +0.0f, +0.0f),
|
||||||
max(max(dg[0].y, dg[0].z), max(dg[1].x, dg[1].w)) // max
|
dg[1], std, dir
|
||||||
);
|
);
|
||||||
vec2 fvy = vec2(
|
mediump vec4 w2 = weightY(
|
||||||
w[0].x + w[0].y + w[0].z + w[0].w,
|
pl.xxxx + vec4(+0.0f, -1.0f, -1.0f, +0.0f),
|
||||||
w[1].x + w[1].y + w[1].z + w[1].w
|
pl.yyyy + vec4(+1.0f, +1.0f, -2.0f, -2.0f),
|
||||||
|
dg[2], std, dir
|
||||||
);
|
);
|
||||||
float fy = clamp((fvy.y / fvy.x) * edge_sharpness, yb[0], yb[1]);
|
mediump float sum_w = dot(w0 + w1 + w2, vec4(1.0f));
|
||||||
// Smooth high contrast input
|
mediump float sum_wc = dot(w0 * dg[0] + w1 * dg[1] + w2 * dg[2], vec4(1.0f));
|
||||||
float dy = clamp(fy - color.y + mean, -23.0f / 255.0f, 23.0f / 255.0f);
|
mediump vec2 yb = vec2(
|
||||||
|
min(min(dg[0].y, dg[0].z), min(dg[1].x, dg[1].w)),
|
||||||
|
max(max(dg[0].y, dg[0].z), max(dg[1].x, dg[1].w))
|
||||||
|
);
|
||||||
|
mediump float fy = clamp((sum_wc / sum_w) * edge_sharpness, yb[0], yb[1]);
|
||||||
|
mediump float dy = clamp(fy - color.y + mean, -23.0f / 255.0f, 23.0f / 255.0f);
|
||||||
color = clamp(color + dy, 0.0f, 1.0f);
|
color = clamp(color + dy, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
color.w = 1.0f; //assume alpha channel is not used
|
color.w = 1.0f;
|
||||||
frag_color.xyzw = color;
|
frag_color.xyzw = color;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user