2017-09-06 19:32:11 -04:00
|
|
|
// pathfinder/shaders/gles2/ssaa-subpixel-resolve.fs.glsl
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2017-12-30 20:32:51 -05:00
|
|
|
//! Performs subpixel antialiasing for LCD screens by converting a
|
|
|
|
//! 3x-oversampled RGBA color buffer to an RGB framebuffer, applying the
|
|
|
|
//! FreeType color defringing filter as necessary.
|
|
|
|
|
2017-09-06 19:32:11 -04:00
|
|
|
precision mediump float;
|
|
|
|
|
|
|
|
uniform sampler2D uSource;
|
|
|
|
uniform ivec2 uSourceDimensions;
|
|
|
|
|
|
|
|
varying vec2 vTexCoord;
|
|
|
|
|
2017-09-06 19:50:36 -04:00
|
|
|
float sampleSource(float deltaX) {
|
2017-11-15 17:36:59 -05:00
|
|
|
return texture2D(uSource, vec2(vTexCoord.x + deltaX, vTexCoord.y)).r;
|
2017-09-06 19:50:36 -04:00
|
|
|
}
|
|
|
|
|
2017-09-06 19:32:11 -04:00
|
|
|
void main() {
|
|
|
|
float onePixel = 1.0 / float(uSourceDimensions.x);
|
2017-09-06 19:50:36 -04:00
|
|
|
|
|
|
|
float shade0 = sampleSource(0.0);
|
|
|
|
vec3 shadeL = vec3(sampleSource(-1.0 * onePixel),
|
|
|
|
sampleSource(-2.0 * onePixel),
|
|
|
|
sampleSource(-3.0 * onePixel));
|
|
|
|
vec3 shadeR = vec3(sampleSource(1.0 * onePixel),
|
|
|
|
sampleSource(2.0 * onePixel),
|
|
|
|
sampleSource(3.0 * onePixel));
|
|
|
|
|
2017-09-19 16:57:56 -04:00
|
|
|
vec3 color = vec3(lcdFilter(shadeL.z, shadeL.y, shadeL.x, shade0, shadeR.x),
|
|
|
|
lcdFilter(shadeL.y, shadeL.x, shade0, shadeR.x, shadeR.y),
|
|
|
|
lcdFilter(shadeL.x, shade0, shadeR.x, shadeR.y, shadeR.z));
|
|
|
|
|
2017-11-15 17:36:59 -05:00
|
|
|
gl_FragColor = vec4(color, 1.0);
|
2017-09-06 19:32:11 -04:00
|
|
|
}
|