slang-shaders/crt/cubic.slang

44 lines
991 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()
{
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()
{
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 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);
}