Commit 35f3d10d authored by hunterk's avatar hunterk
Browse files

add Hyllian's xbr updates and anime4k port

parent 83485c69
shaders = 1
shader0 = shaders/b-spline-fast.slang
filter_linear0 = true
\ No newline at end of file
shaders = 1
shader0 = shaders/catmull-rom-fast.slang
filter_linear0 = true
\ No newline at end of file
#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;
}
\ No newline at end of file
#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));
}
\ No newline at end of file
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"
#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));
}
\ No newline at end of file
#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);
}
\ No newline at end of file
#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;
}
\ No newline at end of file
#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);