diff options
Diffstat (limited to 'assets/shaders/psx_filter.fs')
| -rw-r--r-- | assets/shaders/psx_filter.fs | 38 |
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 |
