Overlay texts were previously drawn with two sets of shadows: - 3px blur, - 5px blur, slightly offset But since the shadow color was always set to black, it was still causing legibility issues when the text itself was dark (set via theme for example). This PR adds a new "outline" BLF text decoration, and uses that for the overlays. And it picks text/outline color depending on the "background" color of the view. Details: - Instead of "shadow level" integer where the only valid options are 0, 3 or 5, have a FontShadowType enum. - Add a new FontShadowType::Outline enum entry, that does a 1px outline by doing a 3x3 dilation in the font shader. - BLF_draw_default_shadowed is changed to do outline, instead of drawing the shadow twice. - In the font shader, instead of encoding shadow type in signs of the glyph_size, pass that as a "flags" vertex attribute. Put font texture channel count into the same flags, so that the vertex size stays the same. - Well actually, vertex size becomes smaller by 4 bytes, since turns out glyph_mode vertex attribute was not used for anything at all. Images in the PR. Co-authored-by: Harley Acheson <harley.acheson@gmail.com> Pull Request: https://projects.blender.org/blender/blender/pulls/121383
30 lines
978 B
GLSL
30 lines
978 B
GLSL
/* SPDX-FileCopyrightText: 2016-2024 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
void main()
|
|
{
|
|
color_flat = col;
|
|
glyph_offset = offset;
|
|
glyph_dim = glyph_size;
|
|
glyph_flags = flags;
|
|
|
|
/* Depending on shadow outline / blur level, we might need to expand the quad. */
|
|
uint shadow_type = flags & 0xF;
|
|
int interp_size = shadow_type > 4 ? 2 : (shadow_type > 0 ? 1 : 0);
|
|
|
|
/* Quad expansion using instanced rendering. */
|
|
float x = float(gl_VertexID % 2);
|
|
float y = float(gl_VertexID / 2);
|
|
vec2 quad = vec2(x, y);
|
|
|
|
vec2 interp_offset = float(interp_size) / abs(pos.zw - pos.xy);
|
|
texCoord_interp = mix(-interp_offset, 1.0 + interp_offset, quad) * vec2(glyph_dim) + vec2(0.5);
|
|
|
|
vec2 final_pos = mix(vec2(ivec2(pos.xy) + ivec2(-interp_size, interp_size)),
|
|
vec2(ivec2(pos.zw) + ivec2(interp_size, -interp_size)),
|
|
quad);
|
|
|
|
gl_Position = ModelViewProjectionMatrix * vec4(final_pos, 0.0, 1.0);
|
|
}
|