ona/debug/crt.frag

53 lines
1.0 KiB
GLSL

#version 430
layout (binding = 0) uniform sampler2D sprite;
layout (location = 0) in vec4 color;
layout (location = 1) in vec2 uv;
layout (location = 0) out vec4 texel;
layout (binding = 0) uniform Effect {
float screen_width;
float screen_height;
float time;
};
vec3 scanline(vec2 coord, vec3 screen)
{
screen.rgb -= sin((coord.y + (time * 29.0))) * 0.02;
return screen;
}
vec2 crt(vec2 coord, float bend)
{
// put in symmetrical coords
coord = (coord - 0.5) * 2.0;
coord *= 1.0;
// deform coords
coord.x *= 1.0 + pow((abs(coord.y) / bend), 2.0);
coord.y *= 1.0 + pow((abs(coord.x) / bend), 2.0);
// transform back to 0.0 - 1.0 space
coord = (coord / 2.0) + 0.5;
return coord;
}
void main()
{
vec2 crtCoords = crt(uv, 4.8);
// Split the color channels
texel.rgb = texture(sprite, crtCoords).rgb;
texel.a = 1;
// HACK: this bend produces a shitty moire pattern.
// Up the bend for the scanline
vec2 screenSpace = crtCoords * vec2(screen_width, screen_height);
texel.rgb = scanline(screenSpace, texel.rgb);
}