pathfinder/shaders/gles2/xcaa-mono-subpixel-resolve....

43 lines
1.6 KiB
Plaintext
Raw Normal View History

// pathfinder/shaders/gles2/xcaa-mono-subpixel-resolve.fs.glsl
2017-09-07 17:58:41 -04:00
//
// Copyright (c) 2017 The Pathfinder Project Developers.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Performs subpixel antialiasing for LCD screens by converting a
//! 3x-oversampled single-channel color buffer to an RGB framebuffer, applying
//! the FreeType color defringing filter as necessary.
2017-09-07 17:58:41 -04:00
precision mediump float;
2018-01-04 21:07:14 -05:00
/// The background color of the monochrome path.
2017-09-07 17:58:41 -04:00
uniform vec4 uBGColor;
2018-01-04 21:07:14 -05:00
/// The foreground color of the monochrome path.
2017-09-07 17:58:41 -04:00
uniform vec4 uFGColor;
2018-01-04 21:07:14 -05:00
/// The alpha coverage texture.
2017-09-07 17:58:41 -04:00
uniform sampler2D uAAAlpha;
2018-01-04 21:07:14 -05:00
/// The dimensions of the alpha coverage texture, in texels.
2017-09-07 17:58:41 -04:00
uniform ivec2 uAAAlphaDimensions;
uniform vec4 uKernel;
2017-09-07 17:58:41 -04:00
varying vec2 vTexCoord;
void main() {
float onePixel = 1.0 / float(uAAAlphaDimensions.x);
vec4 shadesL, shadesR;
float shadeC;
sample9Tap(shadesL, shadeC, shadesR, uAAAlpha, vTexCoord, onePixel, uKernel);
2017-09-07 17:58:41 -04:00
vec3 shades = vec3(convolve7Tap(shadesL, vec3(shadeC, shadesR.xy), uKernel),
convolve7Tap(vec4(shadesL.yzw, shadeC), shadesR.xyz, uKernel),
convolve7Tap(vec4(shadesL.zw, shadeC, shadesR.x), shadesR.yzw, uKernel));
2017-09-07 17:58:41 -04:00
vec3 color = mix(uBGColor.rgb, uFGColor.rgb, shades);
float alpha = any(greaterThan(shades, vec3(0.0))) ? uFGColor.a : uBGColor.a;
gl_FragColor = alpha * vec4(color, 1.0);
2017-09-07 17:58:41 -04:00
}