slang-shaders/crt/shaders/crt-lottes-multipass/horz5minus2.slang

82 lines
2 KiB
Plaintext
Raw Normal View History

2016-07-27 01:27:29 +10:00
#version 450
2016-07-27 13:40:16 +10:00
#define hardPix -3.0
#define brightboost 1
#define shape 2.0
2016-07-27 01:27:29 +10:00
layout(std140, set = 0, binding = 0) uniform UBO
{
2016-07-27 13:40:16 +10:00
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 REFERENCESize;
2016-07-27 01:27:29 +10:00
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
2016-07-27 13:40:16 +10:00
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
2016-07-27 01:27:29 +10:00
// vTexCoord = floor(global.REFERENCESize.xy * TexCoord);
// vTexCoord = (vTexCoord + 0.5) * global.REFERENCESize.zw;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D REFERENCE;
// Nearest emulated sample given floating point position and texel offset.
// Also zero's off screen.
2016-07-27 13:40:16 +10:00
vec3 Fetch(vec2 pos, vec2 off)
{
pos = vTexCoord;//(floor(pos*global.REFERENCESize.xy+off)+vec2(0.5,0.5)) * global.REFERENCESize.zw;
return brightboost * texture(REFERENCE, pos.xy).rgb;
2016-07-27 01:27:29 +10:00
}
// Distance in emulated pixels to nearest texel.
2016-07-27 13:40:16 +10:00
vec2 Dist(vec2 pos)
{
pos = pos*global.REFERENCESize.xy;
return -((pos - floor(pos)) - vec2(0.5));
}
2016-07-27 01:27:29 +10:00
// 1D Gaussian.
2016-07-27 13:40:16 +10:00
float Gaus(float pos, float scale)
{
return exp2(scale*pow(abs(pos), shape));
}
2016-07-27 01:27:29 +10:00
// 5-tap Gaussian filter along horz line.
2016-07-27 13:40:16 +10:00
vec3 Horz5(vec2 pos,float off)
{
vec3 a = Fetch(pos,vec2(-2.0, off));
vec3 b = Fetch(pos,vec2(-1.0, off));
vec3 c = Fetch(pos,vec2( 0.0, off));
vec3 d = Fetch(pos,vec2( 1.0, off));
vec3 e = Fetch(pos,vec2( 2.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = hardPix;
float wa = Gaus(dst - 2.0, scale);
float wb = Gaus(dst - 1.0, scale);
float wc = Gaus(dst + 0.0, scale);
float wd = Gaus(dst + 1.0, scale);
float we = Gaus(dst + 2.0, scale);
// Return filtered sample.
return (a*wa+b*wb+c*wc+d*wd+e*we)/(wa+wb+wc+wd+we);
}
2016-07-27 01:27:29 +10:00
void main()
{
FragColor = vec4(Horz5(vTexCoord, -2.0).rgb, 1.0);
2016-07-27 13:40:16 +10:00
}