diff options
author | Joe Wilm <joe@jwilm.com> | 2016-04-11 08:05:19 -0700 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-04-11 08:05:19 -0700 |
commit | e794bc11b962adef4d6fbbaeb85344cb138376da (patch) | |
tree | 71d0442ca31a24fcb3c8e64f7887d35688f2109b /res/text.f.glsl | |
parent | b84eb9e921c040c4eadaabd8f3087690efa267b6 (diff) | |
download | alacritty-e794bc11b962adef4d6fbbaeb85344cb138376da.tar.gz alacritty-e794bc11b962adef4d6fbbaeb85344cb138376da.zip |
Use subpixel font rendering
OpenGL only supports shared alpha blending. Subpixel font rendering
requires using the font RGB values as alpha masks for the corresponding
RGB channels. To support this, blending is implemented in the fragment
shader.
Diffstat (limited to 'res/text.f.glsl')
-rw-r--r-- | res/text.f.glsl | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/res/text.f.glsl b/res/text.f.glsl index ce9dd41e..7e80a11c 100644 --- a/res/text.f.glsl +++ b/res/text.f.glsl @@ -3,9 +3,28 @@ in vec2 TexCoords; uniform sampler2D mask; uniform vec3 textColor; +uniform vec3 bgColor; + +// SRC = SRC_ALPHA; DST = 1 - SRC_ALPHA +void MyBlend(in vec3 srcValue, + in vec3 dstValue, + in vec3 srcAlpha, + out vec3 blended) +{ + vec3 dstAlpha = vec3(1.0, 1.0, 1.0) - srcAlpha; + vec3 preBlended = (srcValue * srcAlpha + dstValue * dstAlpha); + + blended = vec3(min(1.0, preBlended.x), + min(1.0, preBlended.y), + min(1.0, preBlended.z)); +} void main() { - vec4 sampled = vec4(1.0, 1.0, 1.0, texture(mask, TexCoords).r); - gl_FragColor = vec4(textColor, 1.0) * sampled; + // vec4 red = vec4(sampled.rgb, sampled.r * sampled.g * sampled.b); + // vec4 sampled = vec4(1.0, 1.0, 1.0, texture(mask, TexCoords)); + vec3 blended = vec3(1.0, 1.0, 1.0); + MyBlend(textColor, bgColor, texture(mask, TexCoords).rgb, blended); + + gl_FragColor = vec4(blended, 1.0); } |