aboutsummaryrefslogtreecommitdiff
path: root/assets/shaders/psx_filter.fs
diff options
context:
space:
mode:
authorUneven Prankster <unevenprankster@protonmail.com>2023-11-16 21:12:27 -0300
committerUneven Prankster <unevenprankster@protonmail.com>2023-11-16 21:12:27 -0300
commit2bbf92ad5ae7708bf18ac7ef333e9a979d8d1bde (patch)
treec9d22bb0d73d9cc0c8586e4d31c93a561ea8e910 /assets/shaders/psx_filter.fs
parent1c0cc775732201f4c4d3ee0d6772be786b3b4aa1 (diff)
Working so hard like a soldiermain
Can't afford a thing on TV
Diffstat (limited to 'assets/shaders/psx_filter.fs')
-rw-r--r--assets/shaders/psx_filter.fs38
1 files changed, 38 insertions, 0 deletions
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