Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DrawString does not work when material blend mode is PremultAlpha #73601

Open
pcen opened this issue Feb 19, 2023 · 1 comment
Open

DrawString does not work when material blend mode is PremultAlpha #73601

pcen opened this issue Feb 19, 2023 · 1 comment

Comments

@pcen
Copy link

pcen commented Feb 19, 2023

Godot version

4.0.rc2.mono

System information

MacOS Ventura 13.1, M1, Vulkan 1.2.231

Issue description

Using DrawString with a Node2D where the material blend mode is set to PremultAlpha renders text as solid rectangles instead of the expected text. This happens when the material blend mode is set from the editor, or via an attached script.
With default material:
Screenshot 2023-02-19 at 4 19 46 PM
With CanvasItemMaterial, blend mode set to PremultAlpha:
Screenshot 2023-02-19 at 4 20 47 PM

Steps to reproduce

  • load the included minimal project in Godot 4 rc2
  • run the main scene (TextExample.tscn)
  • comment out lines 13-15 in TextExample.cs to see default material renders text correctly

Minimal reproduction project

TestText.zip

@Calinou
Copy link
Member

Calinou commented Feb 20, 2023

This is due to how premultiplied alpha rendering works. The font's pixels are always white, but its alpha value changes depending on the pixel. However, with premultiplied alpha, this will always result in white pixels being displayed, as the alpha value only determines the blend mode (0.0 = add, 1.0 = mix).

The font texture needs to be generated differently to be rendered correctly with premultiplied alpha. The problem is that doing so breaks rendering with standard alpha rendering (which Godot uses by default for all 2D rendering). The breakage is subtle, but once you start seeing it, you can't unsee it 🙂

An import option in the font could work in theory, but it would break font rendering in any material that doesn't use premultiplied alpha. At this stage, this begs the question whether we should have a project setting to use premultiplied alpha in all 2D rendering by default, which would also adjust font rendering accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants