mirror of
https://github.com/libretro/slang-shaders.git
synced 2024-11-23 08:19:54 +00:00
add Hyllian's xbr updates and anime4k port
This commit is contained in:
parent
83485c6983
commit
35f3d10d25
4
cubic/b-spline-fast.slangp
Executable file
4
cubic/b-spline-fast.slangp
Executable file
@ -0,0 +1,4 @@
|
||||
shaders = 1
|
||||
|
||||
shader0 = shaders/b-spline-fast.slang
|
||||
filter_linear0 = true
|
4
cubic/catmull-rom-fast.slangp
Executable file
4
cubic/catmull-rom-fast.slangp
Executable file
@ -0,0 +1,4 @@
|
||||
shaders = 1
|
||||
|
||||
shader0 = shaders/catmull-rom-fast.slang
|
||||
filter_linear0 = true
|
87
cubic/shaders/b-spline-fast.slang
Executable file
87
cubic/shaders/b-spline-fast.slang
Executable file
@ -0,0 +1,87 @@
|
||||
#version 450
|
||||
|
||||
/*
|
||||
Bicubic B-Spline 4-taps (Fast) - ported by Hyllian - 2020
|
||||
|
||||
The following code is licensed under the MIT license: https://gist.github.com/TheRealMJP/bc503b0b87b643d3505d41eab8b332ae
|
||||
|
||||
Samples a texture with B-Spline filtering, using only 4 texture fetches instead of 16.
|
||||
See http://vec3.ca/bicubic-filtering-in-fewer-taps/ for more details
|
||||
|
||||
ATENTION: This code only work using LINEAR filter sampling set on Retroarch!
|
||||
|
||||
*/
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
} params;
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
|
||||
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at
|
||||
// location [1, 1] in the grid, where [0, 0] is the top left corner.
|
||||
vec2 samplePos = vTexCoord * params.SourceSize.xy;
|
||||
vec2 tc = floor(samplePos - 0.5) + 0.5;
|
||||
|
||||
// Compute the fractional offset from our starting texel to our original sample location, which we'll
|
||||
// feed into the B-Spline function to get our filter weights.
|
||||
vec2 f = samplePos - tc;
|
||||
vec2 f2 = f * f;
|
||||
vec2 f3 = f2 * f;
|
||||
|
||||
// Compute the B-Spline weights using the fractional offset that we calculated earlier.
|
||||
// These equations are pre-expanded based on our knowledge of where the texels will be located,
|
||||
// which lets us avoid having to evaluate a piece-wise function.
|
||||
vec2 w0 = f2 - 0.5 * (f3 + f);
|
||||
vec2 w1 = 1.5 * f3 - 2.5 * f2 + 1.0;
|
||||
vec2 w2 = -1.5 * f3 + 2. * f2 + 0.5 * f;
|
||||
// vec2 w3 = 0.5 * (f3 - f2);
|
||||
vec2 w3 = 1.0 - w0 - w1 - w2; // The sum of weights must be one.
|
||||
|
||||
// Work out weighting factors and sampling offsets that will let us use bilinear filtering to
|
||||
// simultaneously evaluate the 2 samples each from the 4x4 grid.
|
||||
vec2 s0 = w0 + w1;
|
||||
vec2 s1 = w2 + w3;
|
||||
vec2 f0 = w1 / s0;
|
||||
vec2 f1 = w3 / s1;
|
||||
|
||||
// Compute the final UV coordinates we'll use for sampling the texture
|
||||
vec2 t0 = tc - 1. + f0;
|
||||
vec2 t1 = tc + 1. + f1;
|
||||
|
||||
t0 *= params.SourceSize.zw;
|
||||
t1 *= params.SourceSize.zw;
|
||||
|
||||
vec4 c0 = texture(Source, vec2(t0.x, t0.y));
|
||||
vec4 c1 = texture(Source, vec2(t1.x, t0.y));
|
||||
vec4 c2 = texture(Source, vec2(t0.x, t1.y));
|
||||
vec4 c3 = texture(Source, vec2(t1.x, t1.y));
|
||||
|
||||
FragColor = (c0 * s0.x + c1 * s1.x) * s0.y + (c2 * s0.x + c3 * s1.x) * s1.y;
|
||||
}
|
103
cubic/shaders/catmull-rom-fast.slang
Executable file
103
cubic/shaders/catmull-rom-fast.slang
Executable file
@ -0,0 +1,103 @@
|
||||
#version 450
|
||||
|
||||
/*
|
||||
Bicubic Catmull-Rom 9 taps (Fast) - ported by Hyllian - 2020
|
||||
|
||||
The following code is licensed under the MIT license: https://gist.github.com/TheRealMJP/bc503b0b87b643d3505d41eab8b332ae
|
||||
|
||||
Ported from code: https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1
|
||||
|
||||
Samples a texture with Catmull-Rom filtering, using 9 texture fetches instead of 16.
|
||||
See http://vec3.ca/bicubic-filtering-in-fewer-taps/ for more details
|
||||
|
||||
ATENTION: This code only work using LINEAR filter sampling set on Retroarch!
|
||||
|
||||
*/
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
} params;
|
||||
|
||||
#define mul(c,d) (d*c)
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
|
||||
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at
|
||||
// location [1, 1] in the grid, where [0, 0] is the top left corner.
|
||||
vec2 samplePos = vTexCoord * params.SourceSize.xy;
|
||||
vec2 texPos1 = floor(samplePos - 0.5) + 0.5;
|
||||
|
||||
// Compute the fractional offset from our starting texel to our original sample location, which we'll
|
||||
// feed into the Catmull-Rom spline function to get our filter weights.
|
||||
vec2 f = samplePos - texPos1;
|
||||
|
||||
// Compute the Catmull-Rom weights using the fractional offset that we calculated earlier.
|
||||
// These equations are pre-expanded based on our knowledge of where the texels will be located,
|
||||
// which lets us avoid having to evaluate a piece-wise function.
|
||||
vec2 w0 = f * (-0.5 + f * (1.0 - 0.5 * f));
|
||||
vec2 w1 = 1.0 + f * f * (-2.5 + 1.5 * f);
|
||||
vec2 w2 = f * (0.5 + f * (2.0 - 1.5 * f));
|
||||
vec2 w3 = f * f * (-0.5 + 0.5 * f);
|
||||
// vec2 w3 = 1.0 - w0 - w1 - w2;
|
||||
|
||||
// Work out weighting factors and sampling offsets that will let us use bilinear filtering to
|
||||
// simultaneously evaluate the middle 2 samples from the 4x4 grid.
|
||||
vec2 w12 = w1 + w2;
|
||||
vec2 offset12 = w2 / (w1 + w2);
|
||||
|
||||
// Compute the final UV coordinates we'll use for sampling the texture
|
||||
vec2 texPos0 = texPos1 - 1.;
|
||||
vec2 texPos3 = texPos1 + 2.;
|
||||
vec2 texPos12 = texPos1 + offset12;
|
||||
|
||||
texPos0 *= params.SourceSize.zw;
|
||||
texPos3 *= params.SourceSize.zw;
|
||||
texPos12 *= params.SourceSize.zw;
|
||||
|
||||
vec4 c00 = texture(Source, vec2(texPos0.x, texPos0.y));
|
||||
vec4 c10 = texture(Source, vec2(texPos12.x, texPos0.y));
|
||||
vec4 c20 = texture(Source, vec2(texPos3.x, texPos0.y));
|
||||
|
||||
vec4 c01 = texture(Source, vec2(texPos0.x, texPos12.y));
|
||||
vec4 c11 = texture(Source, vec2(texPos12.x, texPos12.y));
|
||||
vec4 c21 = texture(Source, vec2(texPos3.x, texPos12.y));
|
||||
|
||||
vec4 c02 = texture(Source, vec2(texPos0.x, texPos3.y));
|
||||
vec4 c12 = texture(Source, vec2(texPos12.x, texPos3.y));
|
||||
vec4 c22 = texture(Source, vec2(texPos3.x, texPos3.y));
|
||||
|
||||
vec3 wx = vec3(w0.x, w12.x, w3.x);
|
||||
vec3 wy = vec3(w0.y, w12.y, w3.y);
|
||||
|
||||
vec4 c1 = mul(wx, mat3x4(c00, c10, c20));
|
||||
vec4 c2 = mul(wx, mat3x4(c01, c11, c21));
|
||||
vec4 c3 = mul(wx, mat3x4(c02, c12, c22));
|
||||
|
||||
FragColor = mul(wy, mat3x4(c1, c2, c3));
|
||||
}
|
49
sharpen/Anime4k.slangp
Executable file
49
sharpen/Anime4k.slangp
Executable file
@ -0,0 +1,49 @@
|
||||
shaders = 4
|
||||
|
||||
shader0 = "shaders/anime4k/anime4k-compute-lum.slang"
|
||||
filter_linear0 = "false"
|
||||
wrap_mode0 = "clamp_to_border"
|
||||
mipmap_input0 = "false"
|
||||
alias0 = ""
|
||||
float_framebuffer0 = "false"
|
||||
srgb_framebuffer0 = "false"
|
||||
scale_type_x0 = "source"
|
||||
scale_x0 = "1.000000"
|
||||
scale_type_y0 = "source"
|
||||
scale_y0 = "1.000000"
|
||||
|
||||
shader1 = "shaders/anime4k/anime4k-push.slang"
|
||||
filter_linear1 = "false"
|
||||
wrap_mode1 = "clamp_to_border"
|
||||
mipmap_input1 = "false"
|
||||
alias1 = ""
|
||||
float_framebuffer1 = "false"
|
||||
srgb_framebuffer1 = "false"
|
||||
scale_type_x1 = "source"
|
||||
scale_x1 = "1.000000"
|
||||
scale_type_y1 = "source"
|
||||
scale_y1 = "1.000000"
|
||||
|
||||
shader2 = "shaders/anime4k/anime4k-compute-gradient.slang"
|
||||
filter_linear2 = "false"
|
||||
wrap_mode2 = "clamp_to_border"
|
||||
mipmap_input2 = "false"
|
||||
alias2 = ""
|
||||
float_framebuffer2 = "false"
|
||||
srgb_framebuffer2 = "false"
|
||||
scale_type_x2 = "source"
|
||||
scale_x2 = "1.000000"
|
||||
scale_type_y2 = "source"
|
||||
scale_y2 = "1.000000"
|
||||
|
||||
shader3 = "shaders/anime4k/anime4k-pushgrad-weak.slang"
|
||||
filter_linear3 = "false"
|
||||
wrap_mode3 = "clamp_to_border"
|
||||
mipmap_input3 = "false"
|
||||
alias3 = ""
|
||||
float_framebuffer3 = "false"
|
||||
srgb_framebuffer3 = "false"
|
||||
scale_type_x3 = "source"
|
||||
scale_x3 = "1.000000"
|
||||
scale_type_y3 = "source"
|
||||
scale_y3 = "1.000000"
|
90
sharpen/shaders/anime4k/anime4k-compute-gradient.slang
Executable file
90
sharpen/shaders/anime4k/anime4k-compute-gradient.slang
Executable file
@ -0,0 +1,90 @@
|
||||
#version 450
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2019 bloc97
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
} params;
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord * 1.0001;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
float dx = params.SourceSize.z;
|
||||
float dy = params.SourceSize.w;
|
||||
|
||||
vec4 c0 = texture(Source, vTexCoord);
|
||||
|
||||
//[tl t tr]
|
||||
//[ l r]
|
||||
//[bl b br]
|
||||
|
||||
float t = texture(Source, vTexCoord + vec2( 0, -dy)).a;
|
||||
float tl = texture(Source, vTexCoord + vec2(-dx, -dy)).a;
|
||||
float tr = texture(Source, vTexCoord + vec2( dx, -dy)).a;
|
||||
|
||||
float l = texture(Source, vTexCoord + vec2(-dx, 0)).a;
|
||||
float r = texture(Source, vTexCoord + vec2( dx, 0)).a;
|
||||
|
||||
float b = texture(Source, vTexCoord + vec2( 0, dy)).a;
|
||||
float bl = texture(Source, vTexCoord + vec2(-dx, dy)).a;
|
||||
float br = texture(Source, vTexCoord + vec2( dx, dy)).a;
|
||||
|
||||
//Horizontal Gradient
|
||||
//[-1 0 1]
|
||||
//[-2 0 2]
|
||||
//[-1 0 1]
|
||||
float xgrad = (-tl + tr - l - l + r + r - bl + br);
|
||||
|
||||
//Vertical Gradient
|
||||
//[-1 -2 -1]
|
||||
//[ 0 0 0]
|
||||
//[ 1 2 1]
|
||||
float ygrad = (-tl - t - t - tr + bl + b + b + br);
|
||||
|
||||
//Computes the luminance's gradient and saves it in the unused alpha channel
|
||||
FragColor = vec4(c0.r, c0.g, c0.b, 1 - clamp(sqrt(xgrad * xgrad + ygrad * ygrad), 0, 1));
|
||||
}
|
45
sharpen/shaders/anime4k/anime4k-compute-lum.slang
Executable file
45
sharpen/shaders/anime4k/anime4k-compute-lum.slang
Executable file
@ -0,0 +1,45 @@
|
||||
#version 450
|
||||
|
||||
/*
|
||||
Anime4k - Luma shader - ported by Hyllian - 2020
|
||||
*/
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
} params;
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 c0 = texture(Source, vTexCoord);
|
||||
|
||||
//Quick luminance approximation
|
||||
float lum = (c0.r + c0[0].r + c0.g + c0.g + c0.g + c0.b) / 6;
|
||||
|
||||
//Computes the luminance and saves it in the unused alpha channel
|
||||
FragColor = vec4(c0.r, c0.g, c0.b, lum);
|
||||
}
|
153
sharpen/shaders/anime4k/anime4k-push.slang
Executable file
153
sharpen/shaders/anime4k/anime4k-push.slang
Executable file
@ -0,0 +1,153 @@
|
||||
#version 450
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2019 bloc97
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float STRENGTH_PUSH, STRENGTH_GRAD;
|
||||
} params;
|
||||
|
||||
#pragma parameter STRENGTH_PUSH "Luminance strength" 0.3 0.0 1.0 0.1
|
||||
#define STRENGTH_PUSH params.STRENGTH_PUSH
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
float min3(vec4 a, vec4 b, vec4 c) {
|
||||
return min(min(a.a, b.a), c.a);
|
||||
}
|
||||
float max3(vec4 a, vec4 b, vec4 c) {
|
||||
return max(max(a.a, b.a), c.a);
|
||||
}
|
||||
|
||||
vec4 getLargest(vec4 cc, vec4 lightestColor, vec4 a, vec4 b, vec4 c) {
|
||||
vec4 newColor = cc * (1 - STRENGTH_PUSH) + ((a + b + c) / 3) * STRENGTH_PUSH;
|
||||
// vec4 newColor = lerp(cc, ((a + b + c) / 3), STRENGTH_PUSH);
|
||||
if (newColor.a > lightestColor.a) {
|
||||
return newColor;
|
||||
}
|
||||
return lightestColor;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float dx = params.SourceSize.z;
|
||||
float dy = params.SourceSize.w;
|
||||
|
||||
vec4 cc = texture(Source, vTexCoord); //Current Color
|
||||
|
||||
vec4 t = texture(Source, vTexCoord + vec2( 0, -dy));
|
||||
vec4 tl = texture(Source, vTexCoord + vec2(-dx, -dy));
|
||||
vec4 tr = texture(Source, vTexCoord + vec2( dx, -dy));
|
||||
|
||||
vec4 l = texture(Source, vTexCoord + vec2(-dx, 0));
|
||||
vec4 r = texture(Source, vTexCoord + vec2( dx, 0));
|
||||
|
||||
vec4 b = texture(Source, vTexCoord + vec2( 0, dy));
|
||||
vec4 bl = texture(Source, vTexCoord + vec2(-dx, dy));
|
||||
vec4 br = texture(Source, vTexCoord + vec2( dx, dy));
|
||||
|
||||
|
||||
vec4 lightestColor = cc;
|
||||
|
||||
//Kernel 0 and 4
|
||||
float maxDark = max3(br, b, bl);
|
||||
float minLight = min3(tl, t, tr);
|
||||
|
||||
if (minLight > cc.a && minLight > maxDark) {
|
||||
lightestColor = getLargest(cc, lightestColor, tl, t, tr);
|
||||
} else {
|
||||
maxDark = max3(tl, t, tr);
|
||||
minLight = min3(br, b, bl);
|
||||
if (minLight > cc.a && minLight > maxDark) {
|
||||
lightestColor = getLargest(cc, lightestColor, br, b, bl);
|
||||
}
|
||||
}
|
||||
|
||||
//Kernel 1 and 5
|
||||
maxDark = max3(cc, l, b);
|
||||
minLight = min3(r, t, tr);
|
||||
|
||||
if (minLight > maxDark) {
|
||||
lightestColor = getLargest(cc, lightestColor, r, t, tr);
|
||||
} else {
|
||||
maxDark = max3(cc, r, t);
|
||||
minLight = min3(bl, l, b);
|
||||
if (minLight > maxDark) {
|
||||
lightestColor = getLargest(cc, lightestColor, bl, l, b);
|
||||
}
|
||||
}
|
||||
|
||||
//Kernel 2 and 6
|
||||
maxDark = max3(l, tl, bl);
|
||||
minLight = min3(r, br, tr);
|
||||
|
||||
if (minLight > cc.a && minLight > maxDark) {
|
||||
lightestColor = getLargest(cc, lightestColor, r, br, tr);
|
||||
} else {
|
||||
maxDark = max3(r, br, tr);
|
||||
minLight = min3(l, tl, bl);
|
||||
if (minLight > cc.a && minLight > maxDark) {
|
||||
lightestColor = getLargest(cc, lightestColor, l, tl, bl);
|
||||
}
|
||||
}
|
||||
|
||||
//Kernel 3 and 7
|
||||
maxDark = max3(cc, l, t);
|
||||
minLight = min3(r, br, b);
|
||||
|
||||
if (minLight > maxDark) {
|
||||
lightestColor = getLargest(cc, lightestColor, r, br, b);
|
||||
} else {
|
||||
maxDark = max3(cc, r, b);
|
||||
minLight = min3(t, l, tl);
|
||||
if (minLight > maxDark) {
|
||||
lightestColor = getLargest(cc, lightestColor, t, l, tl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FragColor = lightestColor;
|
||||
}
|
157
sharpen/shaders/anime4k/anime4k-pushgrad-weak.slang
Executable file
157
sharpen/shaders/anime4k/anime4k-pushgrad-weak.slang
Executable file
@ -0,0 +1,157 @@
|
||||
#version 450
|
||||
|
||||
// MIT License
|
||||
|
||||
// Copyright (c) 2019 bloc97
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float STRENGTH_PUSH, STRENGTH_GRAD;
|
||||
} params;
|
||||
|
||||
#pragma parameter STRENGTH_GRAD "Gradient strength" 0.3 0.0 1.0 0.1
|
||||
#define STRENGTH_GRAD params.STRENGTH_GRAD
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
//#define strength 0.7
|
||||
|
||||
float min3(vec4 a, vec4 b, vec4 c) {
|
||||
return min(min(a.a, b.a), c.a);
|
||||
}
|
||||
float max3(vec4 a, vec4 b, vec4 c) {
|
||||
return max(max(a.a, b.a), c.a);
|
||||
}
|
||||
|
||||
vec4 getAverage(vec4 cc, vec4 a, vec4 b, vec4 c) {
|
||||
return cc * (1 - STRENGTH_GRAD) + ((a + b + c) / 3) * STRENGTH_GRAD;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float dx = params.SourceSize.z;
|
||||
float dy = params.SourceSize.w;
|
||||
|
||||
vec4 cc = texture(Source, vTexCoord); //Current Color
|
||||
|
||||
vec4 t = texture(Source, vTexCoord + vec2( 0, -dy));
|
||||
vec4 tl = texture(Source, vTexCoord + vec2(-dx, -dy));
|
||||
vec4 tr = texture(Source, vTexCoord + vec2( dx, -dy));
|
||||
|
||||
vec4 l = texture(Source, vTexCoord + vec2(-dx, 0));
|
||||
vec4 r = texture(Source, vTexCoord + vec2( dx, 0));
|
||||
|
||||
vec4 b = texture(Source, vTexCoord + vec2( 0, dy));
|
||||
vec4 bl = texture(Source, vTexCoord + vec2(-dx, dy));
|
||||
vec4 br = texture(Source, vTexCoord + vec2( dx, dy));
|
||||
|
||||
|
||||
vec4 lightestColor = cc;
|
||||
|
||||
//Kernel 0 and 4
|
||||
float maxDark = max3(br, b, bl);
|
||||
float minLight = min3(tl, t, tr);
|
||||
|
||||
if (minLight > cc.a && minLight > maxDark) {
|
||||
FragColor = getAverage(cc, tl, t, tr);
|
||||
return;
|
||||
} else {
|
||||
maxDark = max3(tl, t, tr);
|
||||
minLight = min3(br, b, bl);
|
||||
if (minLight > cc.a && minLight > maxDark) {
|
||||
FragColor = getAverage(cc, br, b, bl);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Kernel 1 and 5
|
||||
maxDark = max3(cc, l, b);
|
||||
minLight = min3(r, t, tr);
|
||||
|
||||
if (minLight > maxDark) {
|
||||
FragColor = getAverage(cc, r, t, tr);
|
||||
return;
|
||||
} else {
|
||||
maxDark = max3(cc, r, t);
|
||||
minLight = min3(bl, l, b);
|
||||
if (minLight > maxDark) {
|
||||
FragColor = getAverage(cc, bl, l, b);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Kernel 2 and 6
|
||||
maxDark = max3(l, tl, bl);
|
||||
minLight = min3(r, br, tr);
|
||||
|
||||
if (minLight > cc.a && minLight > maxDark) {
|
||||
FragColor = getAverage(cc, r, br, tr);
|
||||
return;
|
||||
} else {
|
||||
maxDark = max3(r, br, tr);
|
||||
minLight = min3(l, tl, bl);
|
||||
if (minLight > cc.a && minLight > maxDark) {
|
||||
FragColor = getAverage(cc, l, tl, bl);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Kernel 3 and 7
|
||||
maxDark = max3(cc, l, t);
|
||||
minLight = min3(r, br, b);
|
||||
|
||||
if (minLight > maxDark) {
|
||||
FragColor = getAverage(cc, r, br, b);
|
||||
return;
|
||||
} else {
|
||||
maxDark = max3(cc, r, b);
|
||||
minLight = min3(t, l, tl);
|
||||
if (minLight > maxDark) {
|
||||
FragColor = getAverage(cc, t, l, tl);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
FragColor = cc;
|
||||
}
|
45
xbr/shaders/super-xbr/super-xbr-pass0.slang
Normal file → Executable file
45
xbr/shaders/super-xbr/super-xbr-pass0.slang
Normal file → Executable file
@ -32,7 +32,7 @@ layout(push_constant) uniform Push
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float XBR_EDGE_STR;
|
||||
float XBR_EDGE_STR_P0;
|
||||
float XBR_WEIGHT;
|
||||
float XBR_ANTI_RINGING;
|
||||
float MODE;
|
||||
@ -40,16 +40,14 @@ layout(push_constant) uniform Push
|
||||
float XBR_TEXTURE_SHP;
|
||||
} params;
|
||||
|
||||
#pragma parameter XBR_EDGE_STR "Xbr - Edge Strength p0" 0.6 0.0 5.0 0.2
|
||||
#pragma parameter XBR_WEIGHT "Xbr - Filter Weight" 1.0 0.00 1.50 0.01
|
||||
#pragma parameter XBR_ANTI_RINGING "Xbr - Anti-Ringing Level" 1.0 0.0 1.0 1.0
|
||||
#pragma parameter MODE "Mode - Normal, Details, Adaptive" 0.0 0.0 2.0 1.0
|
||||
#pragma parameter XBR_EDGE_STR_P0 "Xbr - Edge Strength p0" 5.0 0.0 5.0 0.5
|
||||
#pragma parameter XBR_WEIGHT "Xbr - Filter Weight" 1.0 0.00 1.50 0.01
|
||||
#pragma parameter XBR_EDGE_SHP "Adaptive Dynamic Edge Sharp" 0.4 0.0 3.0 0.1
|
||||
#pragma parameter XBR_TEXTURE_SHP "Adaptive Static Edge Sharp" 1.0 0.0 2.0 0.1
|
||||
|
||||
#define XBR_EDGE_STR params.XBR_EDGE_STR
|
||||
#define XBR_EDGE_STR_P0 params.XBR_EDGE_STR_P0
|
||||
#define XBR_WEIGHT params.XBR_WEIGHT
|
||||
#define XBR_ANTI_RINGING params.XBR_ANTI_RINGING
|
||||
#define MODE params.MODE
|
||||
#define XBR_EDGE_SHP params.XBR_EDGE_SHP
|
||||
#define XBR_TEXTURE_SHP params.XBR_TEXTURE_SHP
|
||||
@ -144,32 +142,7 @@ void main()
|
||||
{
|
||||
// settings //
|
||||
float wp1, wp2, wp3, wp4, wp5, wp6, weight1, weight2;
|
||||
if (MODE == 1.0)
|
||||
{
|
||||
wp1 = 1.0;
|
||||
wp2 = 0.0;
|
||||
wp3 = 0.0;
|
||||
wp4 = 1.0;
|
||||
wp5 = -1.0;
|
||||
wp6 = 0.0;
|
||||
|
||||
weight1 = (XBR_WEIGHT*1.29633/10.0);
|
||||
weight2 = (XBR_WEIGHT*1.75068/10.0/2.0);
|
||||
}
|
||||
else if (MODE == 2.0)
|
||||
{
|
||||
wp1 = 1.0;
|
||||
wp2 = 0.0;
|
||||
wp3 = 0.0;
|
||||
wp4 = 2.0;
|
||||
wp5 = -1.0;
|
||||
wp6 = 0.0;
|
||||
|
||||
weight1 = (1.29633/10.0);
|
||||
weight2 = (1.75068/10.0/2.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
wp1 = 2.0;
|
||||
wp2 = 1.0;
|
||||
wp3 = -1.0;
|
||||
@ -179,7 +152,7 @@ void main()
|
||||
|
||||
weight1 = (XBR_WEIGHT*1.29633/10.0);
|
||||
weight2 = (XBR_WEIGHT*1.75068/10.0/2.0);
|
||||
}
|
||||
|
||||
// end settings //
|
||||
|
||||
vec3 P0 = texture(Source, t1.xy).xyz;
|
||||
@ -222,7 +195,7 @@ void main()
|
||||
/* Calc edgeness in horizontal/vertical directions. */
|
||||
float hv_edge = (hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, f, i, e, h, c, i5, b, h5) - hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, e, f, h, i, d, f4, g, i4));
|
||||
|
||||
float limits = XBR_EDGE_STR + 0.000001;
|
||||
float limits = XBR_EDGE_STR_P0 + 0.000001;
|
||||
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
|
||||
|
||||
vec4 w1, w2;
|
||||
@ -238,7 +211,7 @@ void main()
|
||||
w1 = vec4(-wgt1, wgt1+ 0.5, wgt1+ 0.5, -wgt1);
|
||||
w2 = vec4(-wgt2, wgt2+0.25, wgt2+0.25, -wgt2);
|
||||
c3 = mul(w2, mat4x3(P0+2.0*(D+G)+P2, B+2.0*(E+H)+H5, C+2.0*(F+I)+I5, P1+2.0*(F4+I4)+P3))/3.0;
|
||||
c4 = mul(w2, mat4x3(P0+2.0*(C+B)+P1, D+2.0*(F+E)+F4, G+2.0*(I+H)+I4, P2+2.0*(I5+H5)+P3))/3.0;
|
||||
c4 = mul(w2, mat4x3(P0+2.0*(C+B)+P1, D+2.0*(F+E)+F4, G+2.0*(I+H)+I4, P2+2.0*(I5+H5)+P3))/3.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -257,8 +230,8 @@ void main()
|
||||
vec3 color = mix(mix(c1, c2, step(0.0, d_edge)), mix(c3, c4, step(0.0, hv_edge)), 1. - edge_strength);
|
||||
|
||||
/* Anti-ringing code. */
|
||||
vec3 min_sample = min4( E, F, H, I ) + (1.-XBR_ANTI_RINGING)*mix((P2-H)*(F-P1), (P0-E)*(I-P3), step(0.0, d_edge));
|
||||
vec3 max_sample = max4( E, F, H, I ) - (1.-XBR_ANTI_RINGING)*mix((P2-H)*(F-P1), (P0-E)*(I-P3), step(0.0, d_edge));
|
||||
vec3 min_sample = min4( E, F, H, I );
|
||||
vec3 max_sample = max4( E, F, H, I );
|
||||
color = clamp(color, min_sample, max_sample);
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
|
15
xbr/shaders/super-xbr/super-xbr-pass1.slang
Normal file → Executable file
15
xbr/shaders/super-xbr/super-xbr-pass1.slang
Normal file → Executable file
@ -39,8 +39,10 @@ layout(push_constant) uniform Push
|
||||
float MODE;
|
||||
float XBR_EDGE_SHP;
|
||||
float XBR_TEXTURE_SHP;
|
||||
float XBR_EDGE_STR_P1;
|
||||
} params;
|
||||
|
||||
#pragma parameter XBR_EDGE_STR_P1 "Xbr - Edge Strength p1" 0.0 0.0 5.0 0.5
|
||||
#pragma parameter MODE "Mode - Normal, Details, Adaptive" 0.0 0.0 2.0 1.0
|
||||
#pragma parameter XBR_EDGE_SHP "Adaptive Dynamic Edge Sharp" 0.4 0.0 3.0 0.1
|
||||
#pragma parameter XBR_TEXTURE_SHP "Adaptive Static Edge Sharp" 1.0 0.0 2.0 0.1
|
||||
@ -48,6 +50,7 @@ layout(push_constant) uniform Push
|
||||
#define MODE params.MODE
|
||||
#define XBR_EDGE_SHP params.XBR_EDGE_SHP
|
||||
#define XBR_TEXTURE_SHP params.XBR_TEXTURE_SHP
|
||||
#define XBR_EDGE_STR_P1 params.XBR_EDGE_STR_P1
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
@ -128,8 +131,8 @@ void main()
|
||||
wp1 = 1.0;
|
||||
wp2 = 0.0;
|
||||
wp3 = 0.0;
|
||||
wp4 = 1.0;
|
||||
wp5 = -1.0;
|
||||
wp4 = 0.0;
|
||||
wp5 = 0.0;
|
||||
wp6 = 0.0;
|
||||
|
||||
weight1 = (XBR_WEIGHT*1.75068/10.0);
|
||||
@ -166,7 +169,7 @@ void main()
|
||||
vec2 dir = fp - vec2(0.5,0.5);
|
||||
if ((dir.x*dir.y)>0.0)
|
||||
{
|
||||
FragColor = (fp.x>0.5) ? texture(Source, vTexCoord) : texture(Original, vTexCoord);
|
||||
FragColor = mix( texture(Original, vTexCoord), texture(Source, vTexCoord), step(0.0, dir.x));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -212,7 +215,7 @@ void main()
|
||||
/* Calc edgeness in horizontal/vertical directions. */
|
||||
float hv_edge = (hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, f, i, e, h, c, i5, b, h5) - hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, e, f, h, i, d, f4, g, i4));
|
||||
|
||||
float limits = XBR_EDGE_STR + 0.000001;
|
||||
float limits = XBR_EDGE_STR_P1 + 0.000001;
|
||||
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
|
||||
|
||||
vec4 w1, w2;
|
||||
@ -247,8 +250,8 @@ void main()
|
||||
vec3 color = mix(mix(c1, c2, step(0.0, d_edge)), mix(c3, c4, step(0.0, hv_edge)), 1. - edge_strength);
|
||||
|
||||
/* Anti-ringing code. */
|
||||
vec3 min_sample = min4( E, F, H, I ) + (1.-XBR_ANTI_RINGING)*mix((P2-H)*(F-P1), (P0-E)*(I-P3), step(0.0, d_edge));
|
||||
vec3 max_sample = max4( E, F, H, I ) - (1.-XBR_ANTI_RINGING)*mix((P2-H)*(F-P1), (P0-E)*(I-P3), step(0.0, d_edge));
|
||||
vec3 min_sample = min4( E, F, H, I );
|
||||
vec3 max_sample = max4( E, F, H, I );
|
||||
color = clamp(color, min_sample, max_sample);
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
|
0
xbr/shaders/super-xbr/super-xbr-pass1b.slang
Normal file → Executable file
0
xbr/shaders/super-xbr/super-xbr-pass1b.slang
Normal file → Executable file
13
xbr/shaders/super-xbr/super-xbr-pass2.slang
Normal file → Executable file
13
xbr/shaders/super-xbr/super-xbr-pass2.slang
Normal file → Executable file
@ -39,15 +39,18 @@ layout(push_constant) uniform Push
|
||||
float MODE;
|
||||
float XBR_EDGE_SHP;
|
||||
float XBR_TEXTURE_SHP;
|
||||
float XBR_EDGE_STR_P2;
|
||||
} params;
|
||||
|
||||
#pragma parameter MODE "Mode - Normal, Details, Adaptive" 0.0 0.0 2.0 1.0
|
||||
#pragma parameter XBR_EDGE_STR_P2 "Xbr - Edge Strength p2" 5.0 0.0 5.0 0.5
|
||||
#pragma parameter XBR_EDGE_SHP "Adaptive Dynamic Edge Sharp" 0.4 0.0 3.0 0.1
|
||||
#pragma parameter XBR_TEXTURE_SHP "Adaptive Static Edge Sharp" 1.0 0.0 2.0 0.1
|
||||
|
||||
#define MODE params.MODE
|
||||
#define XBR_EDGE_SHP params.XBR_EDGE_SHP
|
||||
#define XBR_TEXTURE_SHP params.XBR_TEXTURE_SHP
|
||||
#define XBR_EDGE_STR_P2 params.XBR_EDGE_STR_P2
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
@ -139,10 +142,10 @@ void main()
|
||||
float wp1, wp2, wp3, wp4, wp5, wp6, weight1, weight2;
|
||||
if (MODE == 1.0)
|
||||
{
|
||||
wp1 = 1.0;
|
||||
wp1 = 0.0;
|
||||
wp2 = 0.0;
|
||||
wp3 = 0.0;
|
||||
wp4 = 0.0;
|
||||
wp4 = 1.0;
|
||||
wp5 = 0.0;
|
||||
wp6 = 0.0;
|
||||
|
||||
@ -225,7 +228,7 @@ void main()
|
||||
/* Calc edgeness in horizontal/vertical directions. */
|
||||
float hv_edge = (hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, f, i, e, h, c, i5, b, h5) - hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, e, f, h, i, d, f4, g, i4));
|
||||
|
||||
float limits = XBR_EDGE_STR + 0.000001;
|
||||
float limits = XBR_EDGE_STR_P2 + 0.000001;
|
||||
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
|
||||
|
||||
vec4 w1, w2;
|
||||
@ -260,8 +263,8 @@ void main()
|
||||
vec3 color = mix(mix(c1, c2, step(0.0, d_edge)), mix(c3, c4, step(0.0, hv_edge)), 1. - edge_strength);
|
||||
|
||||
/* Anti-ringing code. */
|
||||
vec3 min_sample = min4( E, F, H, I ) + (1.-XBR_ANTI_RINGING)*mix((P2-H)*(F-P1), (P0-E)*(I-P3), step(0.0, d_edge));
|
||||
vec3 max_sample = max4( E, F, H, I ) - (1.-XBR_ANTI_RINGING)*mix((P2-H)*(F-P1), (P0-E)*(I-P3), step(0.0, d_edge));
|
||||
vec3 min_sample = min4( E, F, H, I );
|
||||
vec3 max_sample = max4( E, F, H, I );
|
||||
color = clamp(color, min_sample, max_sample);
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
|
261
xbr/shaders/super-xbr/super-xbr-pass3.slang
Executable file
261
xbr/shaders/super-xbr/super-xbr-pass3.slang
Executable file
@ -0,0 +1,261 @@
|
||||
#version 450
|
||||
|
||||
/*
|
||||
|
||||
******* Super XBR Shader - pass1 *******
|
||||
|
||||
Copyright (c) 2015 Hyllian - sergiogdb@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#define XBR_EDGE_STR 0.6
|
||||
#define XBR_WEIGHT 1.0
|
||||
#define XBR_ANTI_RINGING 1.0
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float MODE;
|
||||
float XBR_EDGE_SHP;
|
||||
float XBR_TEXTURE_SHP;
|
||||
float XBR_EDGE_STR_P1;
|
||||
} params;
|
||||
|
||||
#pragma parameter XBR_EDGE_STR_P1 "Xbr - Edge Strength p1" 0.0 0.0 5.0 0.5
|
||||
#pragma parameter MODE "Mode - Normal, Details, Adaptive" 0.0 0.0 2.0 1.0
|
||||
#pragma parameter XBR_EDGE_SHP "Adaptive Dynamic Edge Sharp" 0.4 0.0 3.0 0.1
|
||||
#pragma parameter XBR_TEXTURE_SHP "Adaptive Static Edge Sharp" 1.0 0.0 2.0 0.1
|
||||
|
||||
#define MODE params.MODE
|
||||
#define XBR_EDGE_SHP params.XBR_EDGE_SHP
|
||||
#define XBR_TEXTURE_SHP params.XBR_TEXTURE_SHP
|
||||
#define XBR_EDGE_STR_P1 params.XBR_EDGE_STR_P1
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#define mul(a,b) (b*a)
|
||||
|
||||
const vec3 Y = vec3(.2126, .7152, .0722);
|
||||
|
||||
float RGBtoYUV(vec3 color)
|
||||
{
|
||||
return dot(color, Y);
|
||||
}
|
||||
|
||||
float df(float A, float B)
|
||||
{
|
||||
return abs(A-B);
|
||||
}
|
||||
|
||||
/*
|
||||
P1
|
||||
|P0|B |C |P1| C F4 |a0|b1|c2|d3|
|
||||
|D |E |F |F4| B F I4 |b0|c1|d2|e3| |e1|i1|i2|e2|
|
||||
|G |H |I |I4| P0 E A I P3 |c0|d1|e2|f3| |e3|i3|i4|e4|
|
||||
|P2|H5|I5|P3| D H I5 |d0|e1|f2|g3|
|
||||
G H5
|
||||
P2
|
||||
*/
|
||||
|
||||
float d_wd(float wp1, float wp2, float wp3, float wp4, float wp5, float wp6, float b0, float b1, float c0, float c1, float c2, float d0, float d1, float d2, float d3, float e1, float e2, float e3, float f2, float f3)
|
||||
{
|
||||
return (wp1*(df(c1,c2) + df(c1,c0) + df(e2,e1) + df(e2,e3)) + wp2*(df(d2,d3) + df(d0,d1)) + wp3*(df(d1,d3) + df(d0,d2)) + wp4*df(d1,d2) + wp5*(df(c0,c2) + df(e1,e3)) + wp6*(df(b0,b1) + df(f2,f3)));
|
||||
}
|
||||
|
||||
float hv_wd(float wp1, float wp2, float wp3, float wp4, float wp5, float wp6, float i1, float i2, float i3, float i4, float e1, float e2, float e3, float e4)
|
||||
{
|
||||
return ( wp4*(df(i1,i2)+df(i3,i4)) + wp1*(df(i1,e1)+df(i2,e2)+df(i3,e3)+df(i4,e4)) + wp3*(df(i1,e2)+df(i3,e4)+df(e1,i2)+df(e3,i4)));
|
||||
}
|
||||
|
||||
vec3 min4(vec3 a, vec3 b, vec3 c, vec3 d)
|
||||
{
|
||||
return min(a, min(b, min(c, d)));
|
||||
}
|
||||
vec3 max4(vec3 a, vec3 b, vec3 c, vec3 d)
|
||||
{
|
||||
return max(a, max(b, max(c, d)));
|
||||
}
|
||||
|
||||
float max4float(float a, float b, float c, float d)
|
||||
{
|
||||
return max(a, max(b, max(c, d)));
|
||||
}
|
||||
|
||||
#pragma stage vertex
|
||||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord * 1.0001;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
layout(set = 0, binding = 3) uniform sampler2D PassPrev2;
|
||||
|
||||
#define Original PassPrev2
|
||||
|
||||
void main()
|
||||
{
|
||||
// settings //
|
||||
float wp1, wp2, wp3, wp4, wp5, wp6, weight1, weight2;
|
||||
if (MODE == 1.0)
|
||||
{
|
||||
wp1 = 1.0;
|
||||
wp2 = 0.0;
|
||||
wp3 = 0.0;
|
||||
wp4 = 0.0;
|
||||
wp5 = 0.0;
|
||||
wp6 = 0.0;
|
||||
|
||||
weight1 = (XBR_WEIGHT*1.75068/10.0);
|
||||
weight2 = (XBR_WEIGHT*1.29633/10.0/2.0);
|
||||
}
|
||||
else if (MODE == 2.0)
|
||||
{
|
||||
wp1 = 8.0;
|
||||
wp2 = 0.0;
|
||||
wp3 = 0.0;
|
||||
wp4 = 0.0;
|
||||
wp5 = 0.0;
|
||||
wp6 = 0.0;
|
||||
|
||||
weight1 = (1.75068/10.0);
|
||||
weight2 = (1.29633/10.0/2.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
wp1 = 8.0;
|
||||
wp2 = 0.0;
|
||||
wp3 = 0.0;
|
||||
wp4 = 0.0;
|
||||
wp5 = 0.0;
|
||||
wp6 = 0.0;
|
||||
|
||||
weight1 = (XBR_WEIGHT*1.75068/10.0);
|
||||
weight2 = (XBR_WEIGHT*1.29633/10.0/2.0);
|
||||
}
|
||||
// end settings //
|
||||
|
||||
//Skip pixels on wrong grid
|
||||
vec2 fp = fract(vTexCoord.xy * params.SourceSize.xy);
|
||||
vec2 dir = fp - vec2(0.5,0.5);
|
||||
if ((dir.x*dir.y)>0.0)
|
||||
{
|
||||
FragColor = mix( texture(Original, vTexCoord), texture(Source, vTexCoord), step(0.0, dir.x));
|
||||
}
|
||||
else
|
||||
{
|
||||
vec2 g1 = (fp.x>0.5) ? vec2(0.5/params.SourceSize.x, 0.0) : vec2(0.0, 0.5/params.SourceSize.y);
|
||||
vec2 g2 = (fp.x>0.5) ? vec2(0.0, 0.5/params.SourceSize.y) : vec2(0.5/params.SourceSize.x, 0.0);
|
||||
|
||||
vec3 P0 = texture(Original, vTexCoord -3.0*g1 ).xyz;
|
||||
vec3 P1 = texture(Source, vTexCoord -3.0*g2).xyz;
|
||||
vec3 P2 = texture(Source, vTexCoord +3.0*g2).xyz;
|
||||
vec3 P3 = texture(Original, vTexCoord +3.0*g1 ).xyz;
|
||||
|
||||
vec3 B = texture(Source, vTexCoord -2.0*g1 -g2).xyz;
|
||||
vec3 C = texture(Original, vTexCoord -g1 -2.0*g2).xyz;
|
||||
vec3 D = texture(Source, vTexCoord -2.0*g1 +g2).xyz;
|
||||
vec3 E = texture(Original, vTexCoord -g1 ).xyz;
|
||||
vec3 F = texture(Source, vTexCoord -g2).xyz;
|
||||
vec3 G = texture(Original, vTexCoord -g1 +2.0*g2).xyz;
|
||||
vec3 H = texture(Source, vTexCoord +g2).xyz;
|
||||
vec3 I = texture(Original, vTexCoord +g1 ).xyz;
|
||||
|
||||
vec3 F4 = texture(Original, vTexCoord +g1 -2.0*g2).xyz;
|
||||
vec3 I4 = texture(Source, vTexCoord +2.0*g1 -g2).xyz;
|
||||
vec3 H5 = texture(Original, vTexCoord +g1 +2.0*g2).xyz;
|
||||
vec3 I5 = texture(Source, vTexCoord +2.0*g1 +g2).xyz;
|
||||
|
||||
float b = RGBtoYUV( B );
|
||||
float c = RGBtoYUV( C );
|
||||
float d = RGBtoYUV( D );
|
||||
float e = RGBtoYUV( E );
|
||||
float f = RGBtoYUV( F );
|
||||
float g = RGBtoYUV( G );
|
||||
float h = RGBtoYUV( H );
|
||||
float i = RGBtoYUV( I );
|
||||
|
||||
float i4 = RGBtoYUV( I4 ); float p0 = RGBtoYUV( P0 );
|
||||
float i5 = RGBtoYUV( I5 ); float p1 = RGBtoYUV( P1 );
|
||||
float h5 = RGBtoYUV( H5 ); float p2 = RGBtoYUV( P2 );
|
||||
float f4 = RGBtoYUV( F4 ); float p3 = RGBtoYUV( P3 );
|
||||
|
||||
/* Calc edgeness in diagonal directions. */
|
||||
float d_edge = (d_wd( wp1, wp2, wp3, wp4, wp5, wp6, d, b, g, e, c, p2, h, f, p1, h5, i, f4, i5, i4 ) - d_wd( wp1, wp2, wp3, wp4, wp5, wp6, c, f4, b, f, i4, p0, e, i, p3, d, h, i5, g, h5 ));
|
||||
|
||||
/* Calc edgeness in horizontal/vertical directions. */
|
||||
float hv_edge = (hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, f, i, e, h, c, i5, b, h5) - hv_wd(wp1, wp2, wp3, wp4, wp5, wp6, e, f, h, i, d, f4, g, i4));
|
||||
|
||||
float limits = XBR_EDGE_STR_P1 + 0.000001;
|
||||
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
|
||||
|
||||
vec4 w1, w2;
|
||||
vec3 c3, c4;
|
||||
if (MODE == 2.0)
|
||||
{
|
||||
float contrast = max(max4float(df(e,f),df(e,i),df(e,h),df(f,h)),max(df(f,i),df(h,i)))/(e+0.001);
|
||||
|
||||
float wgt1 = weight1*(smoothstep(0.0, 0.6, contrast)*XBR_EDGE_SHP + XBR_TEXTURE_SHP);
|
||||
float wgt2 = weight2*(smoothstep(0.0, 0.6, contrast)*XBR_EDGE_SHP + XBR_TEXTURE_SHP);
|
||||
|
||||
/* Filter weights. Two taps only. */
|
||||
w1 = vec4(-wgt1, wgt1+ 0.5, wgt1+ 0.5, -wgt1);
|
||||
w2 = vec4(-wgt2, wgt2+0.25, wgt2+0.25, -wgt2);
|
||||
c3 = mul(w2, mat4x3(P0+2.0*(D+G)+P2, B+2.0*(E+H)+H5, C+2.0*(F+I)+I5, P1+2.0*(F4+I4)+P3))/3.0;
|
||||
c4 = mul(w2, mat4x3(P0+2.0*(C+B)+P1, D+2.0*(F+E)+F4, G+2.0*(I+H)+I4, P2+2.0*(I5+H5)+P3))/3.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Filter weights. Two taps only. */
|
||||
w1 = vec4(-weight1, weight1+0.5, weight1+0.5, -weight1);
|
||||
w2 = vec4(-weight2, weight2+0.25, weight2+0.25, -weight2);
|
||||
c3 = mul(w2, mat4x3(D+G, E+H, F+I, F4+I4));
|
||||
c4 = mul(w2, mat4x3(C+B, F+E, I+H, I5+H5));
|
||||
}
|
||||
|
||||
/* Filtering and normalization in four direction generating four colors. */
|
||||
vec3 c1 = mul(w1, mat4x3( P2, H, F, P1 ));
|
||||
vec3 c2 = mul(w1, mat4x3( P0, E, I, P3 ));
|
||||
|
||||
/* Smoothly blends the two strongest directions (one in diagonal and the other in vert/horiz direction). */
|
||||
vec3 color = mix(mix(c1, c2, step(0.0, d_edge)), mix(c3, c4, step(0.0, hv_edge)), 1. - edge_strength);
|
||||
|
||||
/* Anti-ringing code. */
|
||||
vec3 min_sample = min4( E, F, H, I );
|
||||
vec3 max_sample = max4( E, F, H, I );
|
||||
color = clamp(color, min_sample, max_sample);
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
||||
}
|
127
xbr/super-xbr-6p-anime4k.slangp
Executable file
127
xbr/super-xbr-6p-anime4k.slangp
Executable file
@ -0,0 +1,127 @@
|
||||
shaders = "11"
|
||||
shader0 = "shaders/super-xbr/super-xbr-pass0.slang"
|
||||
filter_linear0 = "false"
|
||||
wrap_mode0 = "clamp_to_border"
|
||||
mipmap_input0 = "false"
|
||||
alias0 = ""
|
||||
float_framebuffer0 = "false"
|
||||
srgb_framebuffer0 = "false"
|
||||
scale_type_x0 = "source"
|
||||
scale_x0 = "1.000000"
|
||||
scale_type_y0 = "source"
|
||||
scale_y0 = "1.000000"
|
||||
shader1 = "shaders/super-xbr/super-xbr-pass1.slang"
|
||||
filter_linear1 = "false"
|
||||
wrap_mode1 = "clamp_to_border"
|
||||
mipmap_input1 = "false"
|
||||
alias1 = ""
|
||||
float_framebuffer1 = "false"
|
||||
srgb_framebuffer1 = "false"
|
||||
scale_type_x1 = "source"
|
||||
scale_x1 = "2.000000"
|
||||
scale_type_y1 = "source"
|
||||
scale_y1 = "2.000000"
|
||||
shader2 = "shaders/super-xbr/super-xbr-pass2.slang"
|
||||
filter_linear2 = "false"
|
||||
wrap_mode2 = "clamp_to_border"
|
||||
mipmap_input2 = "false"
|
||||
alias2 = "PassPrev2"
|
||||
float_framebuffer2 = "false"
|
||||
srgb_framebuffer2 = "false"
|
||||
scale_type_x2 = "source"
|
||||
scale_x2 = "1.000000"
|
||||
scale_type_y2 = "source"
|
||||
scale_y2 = "1.000000"
|
||||
shader3 = "shaders/super-xbr/super-xbr-pass0.slang"
|
||||
filter_linear3 = "false"
|
||||
wrap_mode3 = "clamp_to_border"
|
||||
mipmap_input3 = "false"
|
||||
alias3 = ""
|
||||
float_framebuffer3 = "false"
|
||||
srgb_framebuffer3 = "false"
|
||||
scale_type_x3 = "source"
|
||||
scale_x3 = "1.000000"
|
||||
scale_type_y3 = "source"
|
||||
scale_y3 = "1.000000"
|
||||
shader4 = "shaders/super-xbr/super-xbr-pass3.slang"
|
||||
filter_linear4 = "false"
|
||||
wrap_mode4 = "clamp_to_border"
|
||||
mipmap_input4 = "false"
|
||||
alias4 = ""
|
||||
float_framebuffer4 = "false"
|
||||
srgb_framebuffer4 = "false"
|
||||
scale_type_x4 = "source"
|
||||
scale_x4 = "2.000000"
|
||||
scale_type_y4 = "source"
|
||||
scale_y4 = "2.000000"
|
||||
shader5 = "shaders/super-xbr/super-xbr-pass2.slang"
|
||||
filter_linear5 = "false"
|
||||
wrap_mode5 = "clamp_to_border"
|
||||
mipmap_input5 = "false"
|
||||
alias5 = ""
|
||||
float_framebuffer5 = "false"
|
||||
srgb_framebuffer5 = "false"
|
||||
scale_type_x5 = "source"
|
||||
scale_x5 = "1.000000"
|
||||
scale_type_y5 = "source"
|
||||
scale_y5 = "1.000000"
|
||||
shader6 = "../cubic/shaders/catmull-rom-fast.slang"
|
||||
filter_linear6 = "true"
|
||||
wrap_mode6 = "clamp_to_border"
|
||||
mipmap_input6 = "false"
|
||||
alias6 = ""
|
||||
float_framebuffer6 = "false"
|
||||
srgb_framebuffer6 = "false"
|
||||
scale_type_x6 = "viewport"
|
||||
scale_type_y6 = "viewport"
|
||||
shader7 = "../sharpen/shaders/anime4k/anime4k-compute-lum.slang"
|
||||
filter_linear7 = "false"
|
||||
wrap_mode7 = "clamp_to_border"
|
||||
mipmap_input7 = "false"
|
||||
alias7 = ""
|
||||
float_framebuffer7 = "false"
|
||||
srgb_framebuffer7 = "false"
|
||||
scale_type_x7 = "source"
|
||||
scale_x7 = "1.000000"
|
||||
scale_type_y7 = "source"
|
||||
scale_y7 = "1.000000"
|
||||
shader8 = "../sharpen/shaders/anime4k/anime4k-push.slang"
|
||||
filter_linear8 = "false"
|
||||
wrap_mode8 = "clamp_to_border"
|
||||
mipmap_input8 = "false"
|
||||
alias8 = ""
|
||||
float_framebuffer8 = "false"
|
||||
srgb_framebuffer8 = "false"
|
||||
scale_type_x8 = "source"
|
||||
scale_x8 = "1.000000"
|
||||
scale_type_y8 = "source"
|
||||
scale_y8 = "1.000000"
|
||||
shader9 = "../sharpen/shaders/anime4k/anime4k-compute-gradient.slang"
|
||||
filter_linear9 = "false"
|
||||
wrap_mode9 = "clamp_to_border"
|
||||
mipmap_input9 = "false"
|
||||
alias9 = ""
|
||||
float_framebuffer9 = "false"
|
||||
srgb_framebuffer9 = "false"
|
||||
scale_type_x9 = "source"
|
||||
scale_x9 = "1.000000"
|
||||
scale_type_y9 = "source"
|
||||
scale_y9 = "1.000000"
|
||||
shader10 = "../sharpen/shaders/anime4k/anime4k-pushgrad-weak.slang"
|
||||
filter_linear10 = "false"
|
||||
wrap_mode10 = "clamp_to_border"
|
||||
mipmap_input10 = "false"
|
||||
alias10 = ""
|
||||
float_framebuffer10 = "false"
|
||||
srgb_framebuffer10 = "false"
|
||||
scale_type_x10 = "source"
|
||||
scale_x10 = "1.000000"
|
||||
scale_type_y10 = "source"
|
||||
scale_y10 = "1.000000"
|
||||
parameters = "MODE;XBR_EDGE_STR;XBR_WEIGHT;XBR_ANTI_RINGING;XBR_EDGE_STR;XBR_WEIGHT;XBR_ANTI_RINGING;STRENGTH_PUSH;STRENGTH_GRAD"
|
||||
MODE = "1.0"
|
||||
XBR_EDGE_STR = "5.000000"
|
||||
XBR_WEIGHT = "1.000000"
|
||||
XBR_ANTI_RINGING = "1.000000"
|
||||
STRENGTH_PUSH = "0.300000"
|
||||
STRENGTH_GRAD = "0.300000"
|
@ -41,4 +41,4 @@ filter_linear6 = false
|
||||
|
||||
parameters = "MODE;XBR_EDGE_STR"
|
||||
MODE = "1.0"
|
||||
XBR_EDGE_STR = "2.0"
|
||||
XBR_EDGE_STR = "5.0"
|
||||
|
Loading…
Reference in New Issue
Block a user