mlaa_color1.frag 935 B

123456789101112131415161718192021222324252627282930313233
  1. uniform sampler2D colorMapG;
  2. const float threshold = 0.1;
  3. out vec4 FragColor;
  4. void main() {
  5. vec3 weights = vec3(0.2126,0.7152, 0.0722); // ITU-R BT. 709
  6. vec2 uv = gl_FragCoord.xy / u_screen;
  7. vec2 uv_left = uv + vec2(-1., 0.) / u_screen;
  8. vec2 uv_top = uv + vec2(0., 1.) / u_screen;
  9. vec2 uv_right = uv + vec2(1., 0.) / u_screen;
  10. vec2 uv_bottom = uv + vec2(0., -1.) / u_screen;
  11. /**
  12. * Luma calculation requires gamma-corrected colors:
  13. */
  14. float L = dot(texture(colorMapG, uv).rgb, weights);
  15. float Lleft = dot(texture(colorMapG, uv_left).rgb, weights);
  16. float Ltop = dot(texture(colorMapG, uv_top).rgb, weights);
  17. float Lright = dot(texture(colorMapG, uv_right).rgb, weights);
  18. float Lbottom = dot(texture(colorMapG, uv_bottom).rgb, weights);
  19. vec4 delta = abs(vec4(L) - vec4(Lleft, Ltop, Lright, Lbottom));
  20. vec4 edges = step(vec4(threshold), delta);
  21. if (dot(edges, vec4(1.0)) == 0.0)
  22. discard;
  23. FragColor = edges;
  24. }