Archived
1
0
Fork 0
This repository has been archived on 2025-09-02. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
skcblitz/shaders/text.fsh
2025-09-02 14:43:36 +02:00

35 lines
1.3 KiB
GLSL

out vec4 FragColor;
in vec2 tex_coord;
uniform vec2 font_size;
uniform vec4 pad;
uniform vec4 glyph;
uniform vec4 color;
uniform vec4 back;
uniform sampler2D tex;
uniform int flags;
uniform int ch_index;
uniform float time;
#define FLAG_UL 0x01
#define FLAG_CL 0x02
#define FLAG_BL 0x04
#define FLAG_FD 0x08
void main() {
vec2 tex_pos = glyph.st - pad.st + tex_coord * ((glyph.pq + pad.pq) - (glyph.st - pad.st));
if((flags & FLAG_CL) != 0 && tex_pos.y >= floor(font_size.y / 2.0) && tex_pos.y < (floor(font_size.y / 2.0) + 1.0))
FragColor = vec4(0.25, 0.25, 0.25, color.a);
else if((flags & FLAG_UL) != 0 && tex_pos.y >= (font_size.y - 2.0) && tex_pos.y < (font_size.y - 1.0))
FragColor = vec4(0.95, 0.1, 0.1, color.a);
else if(tex_pos.x < glyph.s || tex_pos.x > glyph.p || tex_pos.y < glyph.t || tex_pos.y > glyph.q)
FragColor = vec4(0.0);
else
FragColor = texture(tex, (vec2(float(ch_index & 15), float((ch_index >> 4) & 15)) + (tex_pos / font_size)) / 16.0) * color;
if((flags & FLAG_BL) != 0 && fract(time) >= 0.5)
FragColor = vec4(0.0, 1.0, 0.0, FragColor.a);
if((flags & FLAG_FD) != 0)
FragColor = mix(FragColor, vec4(1.0, 1.0, 1.0, FragColor.a), sin(radians(fract(time + tex_coord.y) * 360.0)) * 0.5 + 0.5);
FragColor = mix(back, FragColor, FragColor.a);
}