cmyk-dot.fs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #version 150
  2. uniform sampler2D source[];
  3. uniform vec4 sourceSize[];
  4. uniform vec4 targetSize;
  5. uniform int phase;
  6. in vec2 st2;
  7. in vec2 nearest;
  8. in vec3 texcolor;
  9. in vec3 white;
  10. in vec3 black;
  11. in vec4 cmyk;
  12. in vec2 Kst;
  13. in vec2 Kuv;
  14. in vec2 Cst;
  15. in vec2 Cuv;
  16. in vec2 Mst;
  17. in vec2 Muv;
  18. in vec2 Yst;
  19. in vec2 Yuv;
  20. in vec3 rgbscreen;
  21. in float value;
  22. in vec3 newcolor;
  23. #define frequency 253
  24. in Vertex {
  25. vec2 texCoord;
  26. };
  27. float aastep(float threshold, float value) {
  28. float afwidth = 0.7 * length(vec2(dFdx(value), dFdy(value)));
  29. return smoothstep(threshold-afwidth, threshold+afwidth, value);
  30. }
  31. out vec4 fragColor;
  32. void main() {
  33. // Sample the colors
  34. vec3 texcolor = texture(source[0], texCoord).rgb;
  35. // Perform a rough RGB-to-CMYK conversion
  36. vec4 cmyk;
  37. cmyk.xyz = 1.0 - texcolor;
  38. cmyk.w = min(cmyk.x, min(cmyk.y, cmyk.z)); // Create K
  39. cmyk.xyz -= cmyk.w; // Subtract K equivalent from CMY
  40. vec3 white = vec3(1.0, 1.0, 1.0);
  41. vec3 black = vec3(0.0, 0.0, 0.0);
  42. // Distance to nearest point in a grid of
  43. // (frequency x frequency) points over the unit square
  44. vec2 Kst = frequency * mat2(0.707, -0.707, 0.707, 0.707) * texCoord;
  45. vec2 Kuv = 2.0 * fract(Kst) - 1.0;
  46. float k = aastep(0.0, sqrt(cmyk.w) - length(Kuv));
  47. vec2 Cst = frequency * mat2(0.966, -0.259, 0.259, 0.966) * texCoord;
  48. vec2 Cuv = 2.0 * fract(Cst) - 1.0;
  49. float c = aastep(0.0, sqrt(cmyk.x) - length(Cuv));
  50. vec2 Mst = frequency * mat2(0.966, 0.259, -0.259, 0.966) * texCoord;
  51. vec2 Muv = 2.0 * fract(Mst) - 1.0;
  52. float m = aastep(0.0, sqrt(cmyk.y) - length(Muv));
  53. vec2 Yst = frequency * texCoord; // 0 deg
  54. vec2 Yuv = 2.0 * fract(Yst) - 1.0;
  55. float y = aastep(0.0, sqrt(cmyk.z) - length(Yuv));
  56. vec3 rgbscreen = 1.0 - vec3(c, m, y);
  57. rgbscreen = mix(rgbscreen, black, k + 0.4);
  58. fragColor = (vec4(rgbscreen * 2.0, 1.0) + vec4(texture(source[0], texCoord).rgba)) / 2.0;
  59. }