BLF: optimizations and fixes to font shader #119653
|
@ -29,7 +29,7 @@ bool is_inside_box(ivec2 v)
|
|||
|
||||
float sample_glyph_bilinear(vec2 bilin_f, vec2 uv)
|
||||
{
|
||||
ivec2 iuv = ivec2(uv) - 1;
|
||||
ivec2 iuv = ivec2(floor(uv)) - 1;
|
||||
aras_p marked this conversation as resolved
Outdated
|
||||
int index = glyph_offset + iuv.y * glyph_dim.x + iuv.x;
|
||||
|
||||
/* Fetch 2x2 texels for filtering. */
|
||||
|
@ -41,10 +41,14 @@ float sample_glyph_bilinear(vec2 bilin_f, vec2 uv)
|
|||
float br = texel_fetch(index + offset_x + offset_y);
|
||||
|
||||
/* Texels outside of glyph box: zero. */
|
||||
if (!is_inside_box(iuv)) tl = 0.0;
|
||||
if (!is_inside_box(iuv + ivec2(1, 0))) tr = 0.0;
|
||||
if (!is_inside_box(iuv + ivec2(0, 1))) bl = 0.0;
|
||||
if (!is_inside_box(iuv + ivec2(1, 1))) br = 0.0;
|
||||
if (!is_inside_box(iuv))
|
||||
tl = 0.0;
|
||||
if (!is_inside_box(iuv + ivec2(1, 0)))
|
||||
tr = 0.0;
|
||||
if (!is_inside_box(iuv + ivec2(0, 1)))
|
||||
bl = 0.0;
|
||||
if (!is_inside_box(iuv + ivec2(1, 1)))
|
||||
br = 0.0;
|
||||
|
||||
/* Bilinear filter. */
|
||||
float tA = mix(tl, tr, bilin_f.x);
|
||||
|
@ -54,7 +58,7 @@ float sample_glyph_bilinear(vec2 bilin_f, vec2 uv)
|
|||
|
||||
vec4 sample_glyph_rgba(vec2 uv)
|
||||
{
|
||||
ivec2 iuv = ivec2(uv) - 1;
|
||||
ivec2 iuv = ivec2(floor(uv)) - 1;
|
||||
|
||||
vec4 col = vec4(0.0);
|
||||
if (is_inside_box(iuv)) {
|
||||
|
@ -91,17 +95,21 @@ void main()
|
|||
* filter kernel weights by bilinear fraction. */
|
||||
fragColor.a = 0.0;
|
||||
|
||||
ivec2 iuv = ivec2(uv_base) - 1;
|
||||
ivec2 iuv = ivec2(floor(uv_base)) - 1;
|
||||
int frag_offset = glyph_offset + iuv.y * glyph_dim.x + iuv.x;
|
||||
|
||||
if (interp_size == 1) {
|
||||
/* 3x3 blur */
|
||||
|
||||
/* clang-format off */
|
||||
const float weights3x3[16] = float[16](
|
||||
1.0, 2.0, 1.0, 0.0,
|
||||
2.0, 4.0, 2.0, 0.0,
|
||||
1.0, 2.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 0.0
|
||||
);
|
||||
/* clang-format on */
|
||||
|
||||
float sum = 0.0;
|
||||
int idx = 0;
|
||||
for (int iy = 0; iy < 4; ++iy) {
|
||||
|
@ -109,18 +117,15 @@ void main()
|
|||
for (int ix = 0; ix < 4; ++ix) {
|
||||
int ofsx = ix - 1;
|
||||
float v = texel_fetch(frag_offset + ofsy * glyph_dim.x + ofsx);
|
||||
if (!is_inside_box(iuv + ivec2(ofsx, ofsy))) v = 0.0;
|
||||
if (!is_inside_box(iuv + ivec2(ofsx, ofsy)))
|
||||
aras_p marked this conversation as resolved
Outdated
Clément Foucault
commented
Always use brackets. See https://developer.blender.org/docs/handbook/guidelines/c_cpp/#braces We also have GLSL guidelines https://developer.blender.org/docs/handbook/guidelines/glsl/ Applies to all this file. Always use brackets. See https://developer.blender.org/docs/handbook/guidelines/c_cpp/#braces
We also have GLSL guidelines https://developer.blender.org/docs/handbook/guidelines/glsl/
Applies to all this file.
|
||||
v = 0.0;
|
||||
|
||||
/* Bilinearly compute filter weight for this sample. */
|
||||
float w00 = weights3x3[idx];
|
||||
float w10 = ix > 0 ? weights3x3[idx-1] : 0.0;
|
||||
float w01 = iy > 0 ? weights3x3[idx-4] : 0.0;
|
||||
float w11 = ix > 0 && iy > 0 ? weights3x3[idx-5] : 0.0;
|
||||
float w = mix(
|
||||
mix(w00, w10, bilin_f.x),
|
||||
mix(w01, w11, bilin_f.x),
|
||||
bilin_f.y
|
||||
);
|
||||
float w10 = ix > 0 ? weights3x3[idx - 1] : 0.0;
|
||||
float w01 = iy > 0 ? weights3x3[idx - 4] : 0.0;
|
||||
float w11 = ix > 0 && iy > 0 ? weights3x3[idx - 5] : 0.0;
|
||||
float w = mix(mix(w00, w10, bilin_f.x), mix(w01, w11, bilin_f.x), bilin_f.y);
|
||||
|
||||
sum += v * w;
|
||||
++idx;
|
||||
|
@ -130,6 +135,8 @@ void main()
|
|||
}
|
||||
else {
|
||||
/* 5x5 blur */
|
||||
|
||||
/* clang-format off */
|
||||
const float weights5x5[36] = float[36](
|
||||
1.0, 2.0, 2.0, 2.0, 1.0, 0.0,
|
||||
2.0, 5.0, 6.0, 5.0, 2.0, 0.0,
|
||||
|
@ -138,6 +145,8 @@ void main()
|
|||
1.0, 2.0, 2.0, 2.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0
|
||||
);
|
||||
/* clang-format on */
|
||||
|
||||
float sum = 0.0;
|
||||
int idx = 0;
|
||||
for (int iy = 0; iy < 6; ++iy) {
|
||||
|
@ -145,18 +154,15 @@ void main()
|
|||
for (int ix = 0; ix < 6; ++ix) {
|
||||
int ofsx = ix - 2;
|
||||
float v = texel_fetch(frag_offset + ofsy * glyph_dim.x + ofsx);
|
||||
if (!is_inside_box(iuv + ivec2(ofsx, ofsy))) v = 0.0;
|
||||
if (!is_inside_box(iuv + ivec2(ofsx, ofsy)))
|
||||
v = 0.0;
|
||||
|
||||
/* Bilinearly compute filter weight for this sample. */
|
||||
float w00 = weights5x5[idx];
|
||||
float w10 = ix > 0 ? weights5x5[idx-1] : 0.0;
|
||||
float w01 = iy > 0 ? weights5x5[idx-6] : 0.0;
|
||||
float w11 = ix > 0 && iy > 0 ? weights5x5[idx-7] : 0.0;
|
||||
float w = mix(
|
||||
mix(w00, w10, bilin_f.x),
|
||||
mix(w01, w11, bilin_f.x),
|
||||
bilin_f.y
|
||||
);
|
||||
float w10 = ix > 0 ? weights5x5[idx - 1] : 0.0;
|
||||
float w01 = iy > 0 ? weights5x5[idx - 6] : 0.0;
|
||||
float w11 = ix > 0 && iy > 0 ? weights5x5[idx - 7] : 0.0;
|
||||
float w = mix(mix(w00, w10, bilin_f.x), mix(w01, w11, bilin_f.x), bilin_f.y);
|
||||
|
||||
sum += v * w;
|
||||
++idx;
|
||||
|
|
Loading…
Reference in New Issue
Rename as
texel
.