slang-shaders/crt/shaders/crt-slangtest/sinc.slang

50 lines
1,015 B
Plaintext
Raw Normal View History

2016-02-17 08:56:22 +11:00
#version 450
2016-03-26 03:34:21 +11:00
#include "common.inc"
2016-02-17 08:56:22 +11:00
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
2016-08-02 21:24:03 +10:00
gl_Position = MVP * Position;
2016-02-17 08:56:22 +11:00
vTexCoord = TexCoord;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
2016-08-03 00:11:44 +10:00
layout(set = 0, binding = 1) uniform sampler2D Source;
2016-02-17 08:56:22 +11:00
#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);
2016-02-24 09:04:48 +11:00
#define TEX(x, y) textureLodOffset(Source, tex, 0.0, ivec2(x, y)).rgb
2016-02-17 08:56:22 +11:00
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);
}