From 2bbf92ad5ae7708bf18ac7ef333e9a979d8d1bde Mon Sep 17 00:00:00 2001 From: Uneven Prankster Date: Thu, 16 Nov 2023 21:12:27 -0300 Subject: Working so hard like a soldier Can't afford a thing on TV --- assets/shaders/psx_filter.fs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 assets/shaders/psx_filter.fs (limited to 'assets/shaders/psx_filter.fs') diff --git a/assets/shaders/psx_filter.fs b/assets/shaders/psx_filter.fs new file mode 100644 index 0000000..21eaada --- /dev/null +++ b/assets/shaders/psx_filter.fs @@ -0,0 +1,38 @@ +#version 330 + +uniform sampler2D texture0; + +in vec2 fragTexCoord; + +out vec4 finalColor; + +const float neareight = 255.0; +vec3 dither(vec3 col, uvec2 fc) +{ + const int mat[16] = int[16] ( + -4, 0, -3, 1, + 2, -2, 3, -1, + -3, 1, -4, 0, + 3, -1, 2, -2 + ); + + ivec3 uncol = ivec3(col * neareight) + mat[(fc.y & uint(3)) * uint(4) + (fc.x & uint(3))]; + return vec3(uncol) / neareight; +} + +vec3 band_color(vec3 lol) +{ + ivec3 res = ivec3(clamp(lol, 0.0, 1.0) * neareight) & ivec3(0xFF); + ivec3 ires = res >> 3; + ivec3 dres = (ires >> 2) & ivec3(7); + res = (ires << 3) | dres; + return vec3(res) / neareight; +} + +void main() +{ + vec4 texelColor = texture(texture0, fragTexCoord); + texelColor.rgb = band_color(dither(texelColor.rgb, uvec2(gl_FragCoord.xy))); + + finalColor = texelColor; +} \ No newline at end of file -- cgit v1.2.3