retro.fs 866 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Retro v2 Shader
  2. // Written by Hyllian / Jararaca
  3. #version 150
  4. uniform sampler2D source[];
  5. uniform vec4 sourceSize[];
  6. uniform vec4 targetSize;
  7. // This value must be between 0.0 (totally black) and 1.0 (nearest neighbor)
  8. #define PIXEL_SIZE 0.64
  9. in Vertex {
  10. vec2 texCoord;
  11. };
  12. out vec4 fragColor;
  13. out vec3 E;
  14. out vec2 fp;
  15. out vec2 ps;
  16. out vec2 f;
  17. out vec3 res;
  18. void main() {
  19. // Reading the texel
  20. vec3 E = pow(texture(source[0], texCoord).xyz, vec3(2.4));
  21. vec2 fp = fract(texCoord.xy * sourceSize[0].xy);
  22. vec2 ps = sourceSize[0].xy / targetSize.xy;
  23. vec2 f = clamp(clamp(fp + 0.5*ps, 0.0, 1.0) - PIXEL_SIZE, vec2(0.0, 0.0), ps)/ps;
  24. float max_coord = max(f.x, f.y);
  25. vec3 res = mix(E*(1.04+fp.x*fp.y), E*0.36, max_coord);
  26. fragColor = vec4(clamp( pow(res, vec3(1.0 / 2.2)), 0.0, 1.0 ), 1.0);
  27. }