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); mTextCache->setOpacity(mThemeOpacity);
} }
void TextComponent::setSaturation(float saturation)
{
mSaturation = saturation;
if (mTextCache)
mTextCache->setSaturation(saturation);
}
void TextComponent::setDimming(float dimming) void TextComponent::setDimming(float dimming)
{ {
mDimming = dimming; mDimming = dimming;

View file

@ -62,6 +62,7 @@ public:
float const getColorOpacity() const override { return mColorOpacity; } float const getColorOpacity() const override { return mColorOpacity; }
void setOpacity(float opacity) override; void setOpacity(float opacity) override;
void setSaturation(float saturation) override;
void setDimming(float dimming) override; void setDimming(float dimming) override;
void setSelectable(bool status) { mSelectable = status; } 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) void TextCache::setDimming(float dimming)
{ {
for (auto it = vertexLists.begin(); it != vertexLists.end(); ++it) { for (auto it = vertexLists.begin(); it != vertexLists.end(); ++it) {

View file

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

View file

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