Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-04-08 01:44:35 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-04-08 01:44:35 +0300
commit987c56c4b6150afb67af245f7d71bc965ed5ffc8 (patch)
treed71991af7eaf446a0810d7296f77e65560cbba3c /source/blender/gpu/shaders
parent1a337074175e51c705de0afd230264ff73e04b4b (diff)
BLF: Opti: Draw only one quad per shadow/blurred glyph.
This port the Blurring of blf fonts to the final drawing shader. We add a bit of extra padding to each glyph so that jittering the texture coord does not sample the neighbor glyphs.
Diffstat (limited to 'source/blender/gpu/shaders')
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_frag.glsl86
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_geom.glsl10
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl10
3 files changed, 97 insertions, 9 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_text_frag.glsl b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl
index 7ff90ad4f21..3e5fdd8b90b 100644
--- a/source/blender/gpu/shaders/gpu_shader_text_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl
@@ -1,15 +1,99 @@
flat in vec4 color_flat;
+flat in vec4 texCoord_rect;
noperspective in vec2 texCoord_interp;
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 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
+);
+
+#define sample_glyph_offset(texco, texel, ofs) texture(glyph, texco + ofs * texel).r
+
void main()
{
// input color replaces texture color
fragColor.rgb = color_flat.rgb;
+ vec2 texel = 1.0 / vec2(textureSize(glyph, 0));
+ vec2 texco = mix(abs(texCoord_rect.xy), abs(texCoord_rect.zw), texCoord_interp);
+
// modulate input alpha & texture alpha
- fragColor.a = color_flat.a * texture(glyph, texCoord_interp).r;
+ if (texCoord_rect.x > 0) {
+ fragColor.a = texture(glyph, texco).r;
+ }
+ else {
+ fragColor.a = 0.0;
+
+ 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];
+ }
+ 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 *= color_flat.a;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_geom.glsl b/source/blender/gpu/shaders/gpu_shader_text_geom.glsl
index d4d86db6bc3..0acd2106f7a 100644
--- a/source/blender/gpu/shaders/gpu_shader_text_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_text_geom.glsl
@@ -9,26 +9,28 @@ in vec4 tex_rect[];
in vec4 color[];
flat out vec4 color_flat;
+flat out vec4 texCoord_rect;
noperspective out vec2 texCoord_interp;
void main()
{
color_flat = color[0];
+ texCoord_rect = tex_rect[0];
gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].xy, 0.0, 1.0));
- texCoord_interp = tex_rect[0].xy;
+ texCoord_interp = vec2(0.0, 0.0);
EmitVertex();
gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].zy, 0.0, 1.0));
- texCoord_interp = tex_rect[0].zy;
+ texCoord_interp = vec2(1.0, 0.0);
EmitVertex();
gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].xw, 0.0, 1.0));
- texCoord_interp = tex_rect[0].xw;
+ texCoord_interp = vec2(0.0, 1.0);
EmitVertex();
gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].zw, 0.0, 1.0));
- texCoord_interp = tex_rect[0].zw;
+ texCoord_interp = vec2(1.0, 1.0);
EmitVertex();
EndPrimitive();
diff --git a/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl b/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl
index 79dc996997b..8903fd1df57 100644
--- a/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl
@@ -7,27 +7,29 @@ in vec4 tex_rect[];
in vec4 color[];
flat out vec4 color_flat;
+flat out vec4 texCoord_rect;
noperspective out vec2 texCoord_interp;
void main()
{
color_flat = color[0];
+ texCoord_rect = tex_rect[0];
gl_Position.zw = vec2(0.0, 1.0);
gl_Position.xy = pos_rect[0].xy;
- texCoord_interp = tex_rect[0].xy;
+ texCoord_interp = vec2(0.0, 0.0);
EmitVertex();
gl_Position.xy = pos_rect[0].zy;
- texCoord_interp = tex_rect[0].zy;
+ texCoord_interp = vec2(1.0, 0.0);
EmitVertex();
gl_Position.xy = pos_rect[0].xw;
- texCoord_interp = tex_rect[0].xw;
+ texCoord_interp = vec2(0.0, 1.0);
EmitVertex();
gl_Position.xy = pos_rect[0].zw;
- texCoord_interp = tex_rect[0].zw;
+ texCoord_interp = vec2(1.0, 1.0);
EmitVertex();
EndPrimitive();