diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-04-08 02:00:55 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-04-08 02:00:55 +0300 |
commit | 3725d82cee97b980e514aed1b226deb91aae9fe6 (patch) | |
tree | bbeb5e045a5170baa302f9bfb2505c609d5ec286 /source | |
parent | 987c56c4b6150afb67af245f7d71bc965ed5ffc8 (diff) |
BLF: Opti: More clever sampling for blured glyphs.
Reduce the number of sampled required for blurring by using filtered
texture samples.
This changes the result a bit but it is not noticable.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenfont/intern/blf_glyph.c | 2 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_text_frag.glsl | 91 |
2 files changed, 34 insertions, 59 deletions
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index 03d5b3ea07f..ad7e482f8e0 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -240,7 +240,7 @@ static void blf_glyph_cache_texture(FontBLF *font, GlyphCacheBLF *gc) glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = gc->textures[gc->texture_current])); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, gc->p2_width, gc->p2_height, 0, GL_RED, GL_UNSIGNED_BYTE, NULL); } diff --git a/source/blender/gpu/shaders/gpu_shader_text_frag.glsl b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl index 3e5fdd8b90b..fbfa4cfcc9d 100644 --- a/source/blender/gpu/shaders/gpu_shader_text_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl @@ -6,32 +6,16 @@ out vec4 fragColor; uniform sampler2D glyph; -const vec2 offsets9[9] = vec2[9]( - vec2(-1.0, -1.0), vec2( 0.0, -1.0), vec2( 1.0, -1.0), - vec2(-1.0, 0.0), vec2( 0.0, 0.0), vec2( 1.0, 0.0), - vec2(-1.0, 1.0), vec2( 0.0, 1.0), vec2( 1.0, 1.0) +const vec2 offsets4[4] = vec2[4]( + vec2(-0.5, 0.5), vec2( 0.5, 0.5), + vec2(-0.5, -0.5), vec2(-0.5, -0.5) ); -const vec2 offsets25[25] = vec2[25]( - vec2(-2.0, -2.0), vec2(-1.0, -2.0), vec2( 0.0, -2.0), vec2( 1.0, -2.0), vec2( 2.0, -2.0), - vec2(-2.0, -1.0), vec2(-1.0, -1.0), vec2( 0.0, -1.0), vec2( 1.0, -1.0), vec2( 2.0, -1.0), - vec2(-2.0, 0.0), vec2(-1.0, 0.0), vec2( 0.0, 0.0), vec2( 1.0, 0.0), vec2( 2.0, 0.0), - vec2(-2.0, 1.0), vec2(-1.0, 1.0), vec2( 0.0, 1.0), vec2( 1.0, 1.0), vec2( 2.0, 1.0), - vec2(-2.0, 2.0), vec2(-1.0, 2.0), vec2( 0.0, 2.0), vec2( 1.0, 2.0), vec2( 2.0, 2.0) -); - -const float weights9[9] = float[9]( - 1.0 / 16.0, 2.0 / 16.0, 1.0 / 16.0, - 2.0 / 16.0, 4.0 / 16.0, 2.0 / 16.0, - 1.0 / 16.0, 2.0 / 16.0, 1.0 / 16.0 -); - -const float weights25[25] = float[25]( - 1.0 / 60.0, 1.0 / 60.0, 2.0 / 60.0, 1.0 / 60.0, 1.0 / 60.0, - 1.0 / 60.0, 3.0 / 60.0, 5.0 / 60.0, 3.0 / 60.0, 1.0 / 60.0, - 2.0 / 60.0, 5.0 / 60.0, 8.0 / 60.0, 5.0 / 60.0, 2.0 / 60.0, - 1.0 / 60.0, 3.0 / 60.0, 5.0 / 60.0, 3.0 / 60.0, 1.0 / 60.0, - 1.0 / 60.0, 1.0 / 60.0, 2.0 / 60.0, 1.0 / 60.0, 1.0 / 60.0 +const vec2 offsets16[16] = vec2[16]( + vec2(-1.5, 1.5), vec2(-0.5, 1.5), vec2( 0.5, 1.5), vec2( 1.5, 1.5), + vec2(-1.5, 0.5), vec2(-0.5, 0.5), vec2( 0.5, 0.5), vec2( 1.5, 0.5), + vec2(-1.5, -0.5), vec2(-0.5, -0.5), vec2( 0.5, -0.5), vec2( 1.5, -0.5), + vec2(-1.5, -1.5), vec2(-0.5, -1.5), vec2( 0.5, -1.5), vec2( 1.5, -1.5) ); #define sample_glyph_offset(texco, texel, ofs) texture(glyph, texco + ofs * texel).r @@ -54,44 +38,35 @@ void main() if (texCoord_rect.w > 0) { /* 3x3 blur */ /* Manual unroll for perf. (stupid glsl compiler) */ - fragColor.a += sample_glyph_offset(texco, texel, offsets9[0]) * weights9[0]; - fragColor.a += sample_glyph_offset(texco, texel, offsets9[1]) * weights9[1]; - fragColor.a += sample_glyph_offset(texco, texel, offsets9[2]) * weights9[2]; - fragColor.a += sample_glyph_offset(texco, texel, offsets9[3]) * weights9[3]; - fragColor.a += sample_glyph_offset(texco, texel, offsets9[4]) * weights9[4]; - fragColor.a += sample_glyph_offset(texco, texel, offsets9[5]) * weights9[5]; - fragColor.a += sample_glyph_offset(texco, texel, offsets9[6]) * weights9[6]; - fragColor.a += sample_glyph_offset(texco, texel, offsets9[7]) * weights9[7]; - fragColor.a += sample_glyph_offset(texco, texel, offsets9[8]) * weights9[8]; + fragColor.a += sample_glyph_offset(texco, texel, offsets4[0]); + fragColor.a += sample_glyph_offset(texco, texel, offsets4[1]); + fragColor.a += sample_glyph_offset(texco, texel, offsets4[2]); + fragColor.a += sample_glyph_offset(texco, texel, offsets4[3]); + fragColor.a *= (1.0 / 4.0); } else { /* 5x5 blur */ /* Manual unroll for perf. (stupid glsl compiler) */ - fragColor.a += sample_glyph_offset(texco, texel, offsets25[ 0]) * weights25[ 0]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[ 1]) * weights25[ 1]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[ 2]) * weights25[ 2]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[ 3]) * weights25[ 3]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[ 4]) * weights25[ 4]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[ 5]) * weights25[ 5]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[ 6]) * weights25[ 6]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[ 7]) * weights25[ 7]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[ 8]) * weights25[ 8]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[ 9]) * weights25[ 9]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[10]) * weights25[10]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[11]) * weights25[11]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[12]) * weights25[12]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[13]) * weights25[13]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[14]) * weights25[14]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[15]) * weights25[15]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[16]) * weights25[16]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[17]) * weights25[17]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[18]) * weights25[18]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[19]) * weights25[19]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[20]) * weights25[20]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[21]) * weights25[21]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[22]) * weights25[22]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[23]) * weights25[23]; - fragColor.a += sample_glyph_offset(texco, texel, offsets25[24]) * weights25[24]; + fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 0]); + fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 1]); + fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 2]); + fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 3]); + + fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 4]); + fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 5]) * 2.0; + fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 6]) * 2.0; + fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 7]); + + fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 8]); + fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 9]) * 2.0; + fragColor.a += sample_glyph_offset(texco, texel, offsets16[10]) * 2.0; + fragColor.a += sample_glyph_offset(texco, texel, offsets16[11]); + + fragColor.a += sample_glyph_offset(texco, texel, offsets16[12]); + fragColor.a += sample_glyph_offset(texco, texel, offsets16[13]); + fragColor.a += sample_glyph_offset(texco, texel, offsets16[14]); + fragColor.a += sample_glyph_offset(texco, texel, offsets16[15]); + fragColor.a *= (1.0 / 20.0); } } |