Add initial CRT-cubic and CRT-lanczos.

This commit is contained in:
Hans-Kristian Arntzen 2016-02-16 22:56:22 +01:00
commit 7b1827a213
7 changed files with 245 additions and 0 deletions

18
crt/crt-cubic.slangp Normal file
View file

@ -0,0 +1,18 @@
shaders = 3
shader0 = linearize.slang
shader1 = cubic.slang
shader2 = scanline.slang
filter_linear0 = false
scale_type0 = source
scale0 = 1.0
srgb_framebuffer0 = true
filter_linear1 = false
scale_type_x1 = viewport
scale_x1 = 1.0
scale_type_y1 = source
scale_y1 = 1.0
srgb_framebuffer1 = true
filter_linear2 = false

18
crt/crt-lanczos.slangp Normal file
View file

@ -0,0 +1,18 @@
shaders = 3
shader0 = linearize.slang
shader1 = sinc.slang
shader2 = scanline.slang
filter_linear0 = false
scale_type0 = source
scale0 = 1.0
srgb_framebuffer0 = true
filter_linear1 = false
scale_type_x1 = viewport
scale_x1 = 1.0
scale_type_y1 = source
scale_y1 = 1.0
srgb_framebuffer1 = true
filter_linear2 = false

51
crt/cubic.slang Normal file
View file

@ -0,0 +1,51 @@
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} 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 PI 3.1415926535
void main()
{
float u = vTexCoord.x * global.SourceSize.x - 0.5;
float a = fract(u);
vec2 tex = vec2((floor(u) + 0.5) * global.SourceSize.z, vTexCoord.y);
#define TEX(x, y) textureLod(Source, tex + vec2(x * global.SourceSize.z, 0.0), 0.0).rgb
vec3 i0 = TEX(-1, 0);
vec3 i1 = TEX( 0, 0);
vec3 i2 = TEX(+1, 0);
vec3 i3 = TEX(+2, 0);
float a2 = a * a;
float a3 = a2 * a;
vec3 color = i1 +
(i2 - i0) * 0.5 * a +
(i0 - (2.5 * i1) + (2.0 * i2) - (0.5 * i3)) * a2 +
((i3 - i0) + 3.0 * (i1 - i2)) * 0.5 * a3;
FragColor = vec4(color, 1.0);
}

32
crt/linearize.slang Normal file
View file

@ -0,0 +1,32 @@
#version 450
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;
vec3 gamma(vec3 v)
{
return pow(v, vec3(2.2));
}
void main()
{
FragColor = vec4(gamma(texture(Source, vTexCoord).rgb), 1.0);
}

12
crt/retroarch.slangp Normal file
View file

@ -0,0 +1,12 @@
shaders = "1"
shader0 = "/home/maister/.config/retroarch/shaders/sinc.slang"
filter_linear0 = "false"
wrap_mode0 = "clamp_to_border"
mipmap_input0 = "false"
alias0 = ""
float_framebuffer0 = "false"
srgb_framebuffer0 = "true"
scale_type_x0 = "viewport"
scale_x0 = "1.000000"
scale_type_y0 = "source"
scale_y0 = "1.000000"

59
crt/scanline.slang Normal file
View file

@ -0,0 +1,59 @@
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} 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;
vec3 invgamma(vec3 v)
{
return pow(v, vec3(1.0 / 2.2));
}
float luma(vec3 col)
{
return dot(col, vec3(0.29, 0.60, 0.11));
}
void main()
{
vec2 tex = vTexCoord * global.SourceSize.xy;
float frac = fract(tex.y) - 0.5;
tex.y = floor(tex.y) + 0.5;
tex = tex * global.SourceSize.zw;
#define TEX(x, y) textureLod(Source, tex + vec2(0, y * global.SourceSize.w), 0.0).rgb
vec3 l0 = TEX(0, -1);
vec3 l1 = TEX(0, 0);
vec3 l2 = TEX(0, 1);
vec3 dist = (3.5 - 1.0 * vec3(luma(l0), luma(l1), luma(l2))) * (frac + vec3(+1.0, 0.0, -1.0));
dist = exp2(-dist * dist);
vec3 color =
dist.x * l0 +
dist.y * l1 +
dist.z * l2;
FragColor = vec4(invgamma(color), 1.0);
}

55
crt/sinc.slang Normal file
View file

@ -0,0 +1,55 @@
#version 450
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} 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 PI 3.1415926535
float sinc(float x)
{
return sin(x) / x;
}
float kernel(float x)
{
x = max(abs(x) * PI, 0.0001);
return sinc(x) * sinc(0.5 * x);
}
void main()
{
float u = vTexCoord.x * global.SourceSize.x - 0.5;
float a = fract(u);
vec2 tex = vec2((floor(u) + 0.5) * global.SourceSize.z, vTexCoord.y);
#define TEX(x, y) textureLod(Source, tex + vec2(x * global.SourceSize.z, 0.0), 0.0).rgb
vec3 color =
kernel(a + 1.0) * TEX(-1, 0) +
kernel(a ) * TEX( 0, 0) +
kernel(a - 1.0) * TEX( 1, 0) +
kernel(a - 2.0) * TEX( 2, 0);
FragColor = vec4(color, 1.0);
}