mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-09-28 18:08:07 +03:00
Only unscaled glyph bitmaps are now cached in regular memory. Scaled glyphs are stored as textures on the GPU. Only the alpha channel on glyph textures is used, with the color being provided as an input to the shader. Outline and bold rendering is improved by using a simple dilate shader. This looks okay but could be improved (the result is a bit blurry still).
48 lines
1.4 KiB
GLSL
48 lines
1.4 KiB
GLSL
/* Copyright (C) 2019 Nunuhara Cabbage <nunuhara@haniwa.technology>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, see <http://gnu.org/licenses/>.
|
|
*/
|
|
|
|
uniform sampler2D tex;
|
|
uniform float threshold;
|
|
uniform vec4 color;
|
|
|
|
in vec2 tex_coord;
|
|
out vec4 frag_color;
|
|
|
|
void main() {
|
|
// the fractional part of threshold becomes a weight value for the
|
|
// edge pixels
|
|
int size = int(floor(threshold));
|
|
int cutoff = size + 1;
|
|
float edge_weight = fract(threshold);
|
|
vec2 tex_size = textureSize(tex, 0).xy;
|
|
|
|
float a_out = 0;
|
|
|
|
for (int x = -cutoff; x <= cutoff; x++) {
|
|
for (int y = -cutoff; y <= cutoff; y++) {
|
|
float d = distance(vec2(x, y), vec2(0, 0));
|
|
if (d > threshold)
|
|
continue;
|
|
float a = texture(tex, tex_coord + vec2(x, y) / tex_size).a;
|
|
if (d > size)
|
|
a *= edge_weight;
|
|
a_out += a;
|
|
}
|
|
}
|
|
|
|
frag_color = vec4(color.rgb, min(a_out, 1.0));
|
|
}
|