DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
4.9KB

  1. /* =========================================================================
  2. * Freetype GL - A C OpenGL Freetype engine
  3. * Platform: Any
  4. * WWW: http://code.google.com/p/freetype-gl/
  5. * -------------------------------------------------------------------------
  6. * Copyright 2011 Nicolas P. Rougier. All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR
  19. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  20. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  21. * EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  22. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * The views and conclusions contained in the software and documentation are
  30. * those of the authors and should not be interpreted as representing official
  31. * policies, either expressed or implied, of Nicolas P. Rougier.
  32. * ========================================================================= */
  33. vec3
  34. energy_distribution( vec4 previous, vec4 current, vec4 next )
  35. {
  36. float primary = 1.0/3.0;
  37. float secondary = 1.0/3.0;
  38. float tertiary = 0.0;
  39. // Energy distribution as explained on:
  40. // http://www.grc.com/freeandclear.htm
  41. //
  42. // .. v..
  43. // RGB RGB RGB
  44. // previous.g + previous.b + current.r + current.g + current.b
  45. //
  46. // . .v. .
  47. // RGB RGB RGB
  48. // previous.b + current.r + current.g + current.b + next.r
  49. //
  50. // ..v ..
  51. // RGB RGB RGB
  52. // current.r + current.g + current.b + next.r + next.g
  53. float r =
  54. tertiary * previous.g +
  55. secondary * previous.b +
  56. primary * current.r +
  57. secondary * current.g +
  58. tertiary * current.b;
  59. float g =
  60. tertiary * previous.b +
  61. secondary * current.r +
  62. primary * current.g +
  63. secondary * current.b +
  64. tertiary * next.r;
  65. float b =
  66. tertiary * current.r +
  67. secondary * current.g +
  68. primary * current.b +
  69. secondary * next.r +
  70. tertiary * next.g;
  71. return vec3(r,g,b);
  72. }
  73. uniform sampler2D texture;
  74. uniform vec3 pixel;
  75. varying float vgamma;
  76. varying float vshift;
  77. void main()
  78. {
  79. vec2 uv = gl_TexCoord[0].xy;
  80. float shift = vshift;
  81. // LCD Off
  82. if( pixel.z == 1.0)
  83. {
  84. float a = texture2D(texture, uv).r;
  85. gl_FragColor = gl_Color * pow( a, 1.0/vgamma );
  86. return;
  87. }
  88. // LCD On
  89. vec4 current = texture2D(texture, uv);
  90. vec4 previous= texture2D(texture, uv+vec2(-1.,0.)*pixel.xy);
  91. vec4 next = texture2D(texture, uv+vec2(+1.,0.)*pixel.xy);
  92. current = pow(current, vec4(1.0/vgamma));
  93. previous= pow(previous, vec4(1.0/vgamma));
  94. float r = current.r;
  95. float g = current.g;
  96. float b = current.b;
  97. if( shift <= 0.333 )
  98. {
  99. float z = shift/0.333;
  100. r = mix(current.r, previous.b, z);
  101. g = mix(current.g, current.r, z);
  102. b = mix(current.b, current.g, z);
  103. }
  104. else if( shift <= 0.666 )
  105. {
  106. float z = (shift-0.33)/0.333;
  107. r = mix(previous.b, previous.g, z);
  108. g = mix(current.r, previous.b, z);
  109. b = mix(current.g, current.r, z);
  110. }
  111. else if( shift < 1.0 )
  112. {
  113. float z = (shift-0.66)/0.334;
  114. r = mix(previous.g, previous.r, z);
  115. g = mix(previous.b, previous.g, z);
  116. b = mix(current.r, previous.b, z);
  117. }
  118. float t = max(max(r,g),b);
  119. vec4 color = vec4(gl_Color.rgb, (r+g+b)/3.0);
  120. color = t*color + (1.0-t)*vec4(r,g,b, min(min(r,g),b));
  121. gl_FragColor = vec4( color.rgb, gl_Color.a*color.a);
  122. // gl_FragColor = vec4(pow(vec3(r,g,b),vec3(1.0/vgamma)),a);
  123. /*
  124. vec3 color = energy_distribution(previous, vec4(r,g,b,1), next);
  125. color = pow( color, vec3(1.0/vgamma));
  126. vec3 color = vec3(r,g,b); //pow( vec3(r,g,b), vec3(1.0/vgamma));
  127. gl_FragColor.rgb = color; //*gl_Color.rgb;
  128. gl_FragColor.a = (color.r+color.g+color.b)/3.0 * gl_Color.a;
  129. */
  130. // gl_FragColor = vec4(pow(vec3(r,g,b),vec3(1.0/vgamma)),a);
  131. //gl_FragColor = vec4(r,g,b,a);
  132. }