SFML community forums

General => Feature requests => Topic started by: mphe on October 12, 2018, 01:40:46 am

Title: Support for blend color
Post by: mphe on October 12, 2018, 01:40:46 am
I was wondering why there's no support for blend colors. There are implementations for all regular blend modes but not for blending with a constant color.

The only way to achieve such a result seems to be by using vertex colors.
But why iterate over the mesh everytime the color changes to update the vertex colors, when there's already a corresponding OpenGL blend mode available?

For certain color effects, like color flashing, you would need to update the vertex colors every frame. Depending on mesh size and the amount of objects that are affected, this seems like quite a bit of unnecessary overhead.

Is there a reason why this isn't supported yet? Are there any plans to support it in the future?
Title: Re: Support for blend color
Post by: AlexAUT on October 12, 2018, 10:39:53 am
Out of curiosity, which blend mode does reproduce that behaviour? List (https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBlendFunc.xhtml)

I would do it with a very simple shader, (https://www.sfml-dev.org/tutorials/2.0/graphics-shader.php) just add one uniform (vec3 or vec4) to the vertex shader and add it to the color of the vertex. I can post a working example if you are not familiar with shaders.


AlexAUT
Title: Re: Support for blend color
Post by: FRex on October 12, 2018, 11:02:25 am
Quote
Out of curiosity, which blend mode does reproduce that behaviour? List
GL_CONSTANT_COLOR?
Title: Re: Support for blend color
Post by: AlexAUT on October 12, 2018, 11:38:31 am
I thought he is trying to add a constant amount to each channel.  ::)
Title: Re: Support for blend color
Post by: FRex on October 12, 2018, 11:48:37 am
Adding isn't what Vertex color does (which he says does the same thing as this blending he wants).
Title: Re: Support for blend color
Post by: mphe on October 12, 2018, 01:54:53 pm
Out of curiosity, which blend mode does reproduce that behaviour? List (https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBlendFunc.xhtml)

As FRex said, GL_CONSTANT_COLOR.
There's also a glBlendColor (https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBlendColor.xhtml) function for setting the corresponding color.

It would be possible with shaders, but that seems a bit overkill for such a simple task.
Title: Re: Support for blend color
Post by: Hapax on October 15, 2018, 09:58:55 pm
Is it this sort of thing that you were wanting?
https://github.com/Hapaxia/Lens/blob/master/Lens/blendColor.frag
Title: Re: Support for blend color
Post by: mphe on October 17, 2018, 03:19:15 pm
No, as far as I know the blend color is multiplied with the pixel color.
And I know this is possible to do with shaders, but that wasn't the question.

The question / feature request was to add support for blend colors in SFML blend modes, as it is already supported in OpenGL by glBlendColor and the GL_CONSTANT_COLOR related modes.
Title: Re: Support for blend color
Post by: eXpl0it3r on October 17, 2018, 08:48:37 pm
What would you propose as an API design?
Title: Re: Support for blend color
Post by: FRex on October 17, 2018, 09:22:25 pm
Add more enum values to Factor and a Color field to BlendMode and apply it in applyBlendMode if factor is one for GL_CONSTANT_COLOR?
Title: Re: Support for blend color
Post by: mphe on October 18, 2018, 03:10:06 am
Agree with FRex.
Seems like the most straight forward design for this.
Title: Re: Support for blend color
Post by: FRex on October 20, 2018, 02:14:31 am
Should I open an issue for this?
Title: Re: Support for blend color
Post by: mphe on October 25, 2018, 09:47:16 pm
Not sure if that question goes to exploiter or me, but in case of the latter: yes, please
Title: Re: Support for blend color
Post by: FRex on October 25, 2018, 11:01:47 pm
I was asking like Exploiter or Laurent. :P
Title: Re: Support for blend color
Post by: eXpl0it3r on October 26, 2018, 12:22:17 am
Yes, please. :)
Title: Re: Support for blend color
Post by: FRex on October 26, 2018, 01:46:50 am
The issue template gave me a chuckle. :P

I think only people with rights can apply labels like enhancement and so on.

https://github.com/SFML/SFML/issues/1503

Edit: Why do I always get first post on second page of a thread, lol.