BLF: fade out shadow when text color itself is dark #121222

Closed
Aras Pranckevicius wants to merge 1 commits from aras_p/blender:blf_shadow_color into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

Spawned by discussion in chat: https://blender.chat/channel/sequencer-module?msg=PuiLkG3KfrGAhCeHa

BLF_draw_default_shadowed and one place in view2d_draw were using black text shadow color, even if the text itself might be dark enough already (since the color is coming from a theme). So e.g. a black text would result in additional black shadow, which only makes everything more muddy:
shadow_black_current.png

Make these places fade out the shadow: when color luminance is below 0.5 the shadow starts to fade out, and is completely got when luminance drops below 0.25. This is done by the new helper function
BLF_shadow_auto_color.
blender_0429_211457.gif

Python API (blf.shadow) and other existing cases of BLF_shadow remain unchanged.

Spawned by discussion in chat: https://blender.chat/channel/sequencer-module?msg=PuiLkG3KfrGAhCeHa `BLF_draw_default_shadowed` and one place in `view2d_draw` were using black text shadow color, even if the text itself might be dark enough already (since the color is coming from a theme). So e.g. a black text would result in additional black shadow, which only makes everything more muddy: ![shadow_black_current.png](/attachments/8bb0b238-ee09-413f-b3be-6625be85f7e4) Make these places fade out the shadow: when color luminance is below 0.5 the shadow starts to fade out, and is completely got when luminance drops below 0.25. This is done by the new helper function `BLF_shadow_auto_color`. ![blender_0429_211457.gif](/attachments/314e174e-e512-49ae-8d12-b6b60dff7f1c) Python API (`blf.shadow`) and other existing cases of `BLF_shadow` remain unchanged.
Aras Pranckevicius added 1 commit 2024-04-29 20:17:59 +02:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
30b04aa73d
BLF: fade out shadow when text color itself is dark
BLF_draw_default_shadowed and one place in view2d_draw were using
black text shadow color, even if the text itself might be dark
enough already (since the color is coming from a theme).

Make these places fade out the shadow: when color luminance is below
0.5 the shadow starts to fade out, and is completely got when luminance
drops below 0.25. This is done by the new helper function
BLF_shadow_auto_color.

Python API (blf.shadow) and other existing cases of BLF_shadow remain
unchanged.
Aras Pranckevicius requested review from Pablo Vazquez 2024-04-29 20:18:11 +02:00
Aras Pranckevicius requested review from Harley Acheson 2024-04-29 20:18:55 +02:00
Author
Member

@blender-bot build

@blender-bot build
Member

I should start by saying that yes, the overlay text drawing is a problem. And I have struggled with it forever.

That said, I'm not certain this gets us very far. It does make the dark text look better on a light background for sure. But the auto shadow color here does so with very little context, in that it can only do so based on the text color.

For example, this PR changes draw_vertical_scale_indicators to use this. I think this is for drawing the numbers on the vertical axis in Graph Editor. The text shadow there now is set to a (dumb) black. And this PR just makes it use something better if the text color is made brighter. But that removes contrast in that case. So that could be fixed by replacing that black with the background color:

  float shadow_color[4];
  UI_GetThemeColor4fv(TH_BACK, shadow_color);
  BLF_shadow(font_id, 5, shadow_color);

This way the text color and its shadow have the same contrast as TH_TEXT and TH_BACK. And using the background color you wouldn't get that "glow" effect when using a white shadow color. You wouldn't notice the shadow at all unless something is placed under it that is far off the background color.

The 3DView overlay text is an entirely different problem though. We could make that BLF_draw_default_shadowed smarter, and give it a default parameter of shadow color. So it just uses black unless you supply a specific color.

But 3DView can have a background color that is very dark or completely white, yet we only have a single theme setting for text color. So if you set a color that looks good for Grease Pencil it will be bad for regular views.

We do have a ED_view3d_background_color_get that does an okay job of getting a background color. So we use that to manufacture both the text and shadow colors. So when the background is dark we use a black shadow and light text, and if a light background use black text and shadow of background color. Basically allow the shadow to get as dark as black, but not allow it to get lighter than the background - which avoid glowing.

I'll make a different PR so we can stare at it.

I should start by saying that yes, the overlay text drawing is a problem. And I have struggled with it forever. That said, I'm not certain this gets us very far. It does make the dark text look better on a light background for sure. But the auto shadow color here does so with very little context, in that it can only do so based on the text color. For example, this PR changes `draw_vertical_scale_indicators` to use this. I think this is for drawing the numbers on the vertical axis in Graph Editor. The text shadow there now is set to a (dumb) black. And this PR just makes it use something better if the text color is made brighter. But that removes contrast in that case. So that could be fixed by replacing that black with the background color: ``` float shadow_color[4]; UI_GetThemeColor4fv(TH_BACK, shadow_color); BLF_shadow(font_id, 5, shadow_color); ``` This way the text color and its shadow have the same contrast as TH_TEXT and TH_BACK. And using the background color you wouldn't get that "glow" effect when using a white shadow color. You wouldn't notice the shadow at all unless something is placed under it that is far off the background color. The 3DView overlay text is an entirely different problem though. We could make that `BLF_draw_default_shadowed` smarter, and give it a default parameter of shadow color. So it just uses black unless you supply a specific color. But 3DView can have a background color that is very dark or completely white, yet we only have a single theme setting for text color. So if you set a color that looks good for Grease Pencil it will be bad for regular views. We do have a `ED_view3d_background_color_get` that does an _okay_ job of getting a background color. So we use that to manufacture both the text and shadow colors. So when the background is dark we use a black shadow and light text, and if a light background use black text and shadow of background color. Basically allow the shadow to get as dark as black, but not allow it to get lighter than the background - which avoid glowing. I'll make a different PR so we can stare at it.
Author
Member

Closing this in favor of #121239

Closing this in favor of #121239
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.

Pull request closed

Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
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
EEVEE & Viewport
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
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
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
EEVEE & Viewport
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
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
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
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#121222
No description provided.