Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Drawing Text on transparent RenderTexture leaves outline  (Read 11191 times)

0 Members and 1 Guest are viewing this topic.

dialer

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Drawing Text on transparent RenderTexture leaves outline
« Reply #15 on: August 19, 2017, 11:43:58 pm »
No, that's not how this works.

Multiplying an alpha value of 0.5 to a color value of (1, 0, 0) yields a premultiplied color value of (1, 0, 0, 0.5).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing Text on transparent RenderTexture leaves outline
« Reply #16 on: August 20, 2017, 09:13:57 am »
Quote
this refers to the Porter-Duff compositing mode "Source Over", and if it does not, well, that's a bug because it should.

The color and alpha formulae for this mode are:

co = αs x Cs + αb x Cb x (1 – αs)
αo = αs + αb x (1 – αs)
"this refers to", "this mode", ... what is "this"? That's clearly not the correct formula for the "default" alpha-blending mode in SFML, and if "this" refers to another blending mode, then you'd rather talk in SFML or OpenGL terms; using generic terms and formulas won't help to solve this specific issue.

Quote
No, that's not how this works.

Multiplying an alpha value of 0.5 to a color value of (1, 0, 0) yields a premultiplied color value of (1, 0, 0, 0.5).
In which world? Remember that we are in the SFML (and OpenGL) world here... so please refer to the OpenGL blending equations, which are clearly documented in the OpenGL specification.
Laurent Gomila - SFML developer

Xorton

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Drawing Text on transparent RenderTexture leaves outline
« Reply #17 on: August 20, 2017, 02:33:58 pm »
Multiplying an alpha value of 0.5 to a color value of (1, 0, 0) yields a premultiplied color value of (1, 0, 0, 0.5).

In formulas there is no color or alpha values. They are just vectors. And if you multiply vector (1, 0, 0) by scalar 0.5 you'll get vector  (0.5, 0, 0).

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Drawing Text on transparent RenderTexture leaves outline
« Reply #18 on: August 23, 2017, 01:36:39 pm »
Since I stumbled up on it, I might as well link dialer's SO question related to this topic and his realization that one can't just assume that OpenGL must be doing Source Over with AlphaBlend.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Xorton

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Drawing Text on transparent RenderTexture leaves outline
« Reply #19 on: August 30, 2017, 07:16:39 pm »
Here is my new solution:
https://gist.github.com/Xorton/b88c1a3a1701ceb992c5922a701bda69

Main idea:
1. Move alpha multiplying from blend state to shader (instead of custom blend mode).
2. Use separate texture as mask to define fully transparent background regions (to avoid using same texture for reading and writing).