Added support for changing the saturation for font textures.

This commit is contained in:
Leon Styhre 2023-03-03 22:37:39 +01:00
parent 885a225525
commit d9f38dab3e
5 changed files with 26 additions and 2 deletions

View file

@ -115,6 +115,13 @@ void TextComponent::setOpacity(float opacity)
mTextCache->setOpacity(mThemeOpacity);
}
void TextComponent::setSaturation(float saturation)
{
mSaturation = saturation;
if (mTextCache)
mTextCache->setSaturation(saturation);
}
void TextComponent::setDimming(float dimming)
{
mDimming = dimming;

View file

@ -62,6 +62,7 @@ public:
float const getColorOpacity() const override { return mColorOpacity; }
void setOpacity(float opacity) override;
void setSaturation(float saturation) override;
void setDimming(float dimming) override;
void setSelectable(bool status) { mSelectable = status; }

View file

@ -826,6 +826,14 @@ void TextCache::setOpacity(float opacity)
}
}
void TextCache::setSaturation(float saturation)
{
for (auto it = vertexLists.begin(); it != vertexLists.end(); ++it) {
for (auto it2 = it->verts.begin(); it2 != it->verts.end(); ++it2)
it2->saturation = saturation;
}
}
void TextCache::setDimming(float dimming)
{
for (auto it = vertexLists.begin(); it != vertexLists.end(); ++it) {

View file

@ -238,6 +238,7 @@ public:
void setColor(unsigned int color);
void setOpacity(float opacity);
void setSaturation(float saturation);
void setDimming(float dimming);
friend Font;

View file

@ -79,8 +79,8 @@ void main()
sampledColor.rgb *= sampledColor.a;
}
// Saturation.
if (saturation != 1.0) {
// Saturation, except for font textures.
if (saturation != 1.0 && 0x0u == (shaderFlags & 0x2u)) {
vec3 grayscale;
// Premultiplied textures are all in BGRA format.
if (0x0u != (shaderFlags & 0x01u))
@ -105,6 +105,13 @@ void main()
sampledColor *= color;
}
// Saturation for font textures.
if (saturation != 1.0 && 0x0u != (shaderFlags & 0x2u)) {
vec3 grayscale = vec3(dot(sampledColor.rgb, vec3(0.299, 0.587, 0.114)));
vec3 blendedColor = mix(grayscale, sampledColor.rgb, saturation);
sampledColor = vec4(blendedColor, sampledColor.a);
}
// When post-processing we drop the alpha channel to avoid strange issues with some
// graphics drivers.
if (0x0u != (shaderFlags & 0x4u))