BLF: optimizations and fixes to font shader #119653
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#119653
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "aras_p/blender:text-shader-opt"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
A discussion on chat mentioned that among the shaders that are always initialized upon Blender startup, the text/font shader is taking the longest to compile (usually only 1st time when running a particular blender version). So this PR tries to simplify/optimize that shader. It runs faster now too, but text rasterization is usually not an actual performance problem.
glyph_tex_size
uniform from CPU side to contain the needed data.Fixes while I'm at it
As a result of these fixes, the blur looks a tiny bit different. Not really noticeable for regular text, but here's a screenshot with really scaled up text (at small font size), created from Python script. White text, plus 5 blur, plus 3 blur both in orange, current main branch:
And here's the same in this PR:
First time initialization
Shader performance/complexity
Performance I only measured on macOS (M1 Max), by making a BLF text that is scaled up to cover most of screen via Python. Using Xcode Metal profiler, drawing that text with 5x5 shadow blur: 1.5ms -> 0.3ms.
There aren't that many tools that can tell how "fast" a particular shader is, especially for OpenGL. Several that I found:
WIP: BLF: optimize text shader (mostly for compile time)to WIP: BLF: optimizations and fixes to font shaderWIP: BLF: optimizations and fixes to font shaderto BLF: optimizations and fixes to font shader@blender-bot build
@ -15,3 +18,1 @@
return texelFetch(glyph, ivec2(index % size_x, index / size_x), 0).r;
}
return texelFetch(glyph, ivec2(index, 0), 0).r;
/* glyph_tex_size: upper 8 bits is log2 of texture width, lower 24 bits is width-1 */
Does it really helps to have
glyph_tex_size
encoded as one uniform? I would rather see two uniforms for clarity and less code on the GLSL side.Indeed, two uniforms is cleaner
@ -18,0 +18,4 @@
/* glyph_tex_size: upper 8 bits is log2 of texture width, lower 24 bits is width-1 */
int col_mask = glyph_tex_size & 0xFFFFFF;
int row_shift = glyph_tex_size >> 24;
ivec2 uv = ivec2(index & col_mask, index >> row_shift);
We use
texel
for pixel coordinate, otherwise it's confusing.Should definitely be added to the style guide (done).
Ah, good to know! Without being aware of the style guide, I would have guessed that "texel" would refer to actual texel color/value, not "texel location". But if style guide says so, so be it.
@ -27,3 +32,1 @@
vec2 texel_2d = uv * vec2(glyph_dim) + vec2(0.5);
ivec2 texel_2d_near = ivec2(texel_2d) - 1;
int frag_offset = glyph_offset + texel_2d_near.y * glyph_dim.x + texel_2d_near.x;
ivec2 iuv = ivec2(floor(uv)) - 1;
Rename as
texel
.@ -118,0 +117,4 @@
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)))
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.
Looking back at your screenshot, the second orange line seems less bright. Why so? And which one is the correct one?
@ -161,0 +168,4 @@
++idx;
}
}
fragColor.a = sum * (1.0 / 80.0);
Why
80
and not36
?It is the sum of all the weights. Just like previous code was dividing by 20, not by 16.
Because the 3x3 filter was incorrect due to a copy-paste error. The effective kernel weights were:
instead of what it was trying to do,
So effectively it was over-weighting one corner of the filter, and not taking one texel into account at all. So it is less "blurred" than expected, and hence looks a bit brighter.
I might be missing something, but what kind of font shader is this commit about? Is it available as a texture in the shader graph?
If that's not the case, what kind of text drawing techniques are used on the screenshots that support blurring?
If this is an inappropriate place to ask those questions, please, refer to the right one. Thanks a lot!
Just to make sure, this is not about material shaders that eevee and cycles use. If you want to see details, you can check
Files Changed
tab in top of the page.@DamianWinnichenko this is an internal shader that Blender uses to drawn it's own user interface fonts/texts. It is not usable/relevant/exposed to users in any way.
Thanks for answering!
Will request that feature on right click select then. =)