pathfinder/shaders/filter_text.fs.glsl

62 lines
1.8 KiB
Plaintext
Raw Normal View History

#version 330
// pathfinder/shaders/filter_text.fs.glsl
//
// Copyright © 2019 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.
// TODO(pcwalton): This could be significantly optimized by operating on a
// sparse per-tile basis.
#extension GL_GOOGLE_include_directive : enable
precision highp float;
uniform sampler2D uSource;
uniform vec2 uSourceSize;
uniform vec4 uFGColor;
uniform vec4 uBGColor;
uniform int uGammaCorrectionEnabled;
in vec2 vTexCoord;
out vec4 oFragColor;
#include "filter_text_gamma_correct.inc.glsl"
#include "filter_text_convolve.inc.glsl"
2019-02-05 23:10:20 -05:00
// Convolve horizontally in this pass.
float sample1Tap(float offset) {
return texture(uSource, vec2(vTexCoord.x + offset, vTexCoord.y)).r;
}
void main() {
2019-02-05 23:10:20 -05:00
// Apply defringing if necessary.
vec3 alpha;
if (uKernel.w == 0.0) {
alpha = texture(uSource, vTexCoord).rrr;
} else {
2019-02-05 23:10:20 -05:00
vec4 alphaLeft, alphaRight;
float alphaCenter;
sample9Tap(alphaLeft, alphaCenter, alphaRight, 1.0 / uSourceSize.x);
2019-02-05 23:10:20 -05:00
float r = convolve7Tap(alphaLeft, vec3(alphaCenter, alphaRight.xy));
float g = convolve7Tap(vec4(alphaLeft.yzw, alphaCenter), alphaRight.xyz);
float b = convolve7Tap(vec4(alphaLeft.zw, alphaCenter, alphaRight.x), alphaRight.yzw);
alpha = vec3(r, g, b);
2019-02-05 23:10:20 -05:00
}
2019-02-05 23:10:20 -05:00
// Apply gamma correction if necessary.
if (uGammaCorrectionEnabled != 0)
alpha = gammaCorrect(uBGColor.rgb, alpha);
2019-02-05 23:10:20 -05:00
// Finish.
oFragColor = vec4(mix(uBGColor.rgb, uFGColor.rgb, alpha), 1.0);
}