Fixed an issue where lowered saturation could not be combined with color shifts.

This commit is contained in:
Leon Styhre 2022-12-12 20:21:22 +01:00
parent 19111a9c24
commit 0ad339d4c4

View file

@ -4,7 +4,7 @@
// core.glsl
//
// Core shader functionality:
// Clipping, opacity, saturation, dimming and reflections falloff.
// Clipping, saturation, opacity, dimming and reflections falloff.
//
// Vertex section of code:
@ -39,8 +39,8 @@ in vec2 texCoord;
in vec4 color;
uniform vec4 clipRegion;
uniform float opacity;
uniform float saturation;
uniform float opacity;
uniform float dimming;
uniform float reflectionsFalloff;
uniform uint shaderFlags;
@ -70,6 +70,18 @@ void main()
vec4 sampledColor = texture(textureSampler, texCoord);
// Saturation.
if (saturation != 1.0) {
vec3 grayscale;
// Premultiplied textures are all in BGRA format.
if (0x0u != (shaderFlags & 0x01u))
grayscale = vec3(dot(sampledColor.bgr, vec3(0.0721, 0.7154, 0.2125)));
else
grayscale = vec3(dot(sampledColor.rgb, vec3(0.2125, 0.7154, 0.0721)));
vec3 blendedColor = mix(grayscale, sampledColor.rgb, saturation);
sampledColor = vec4(blendedColor, sampledColor.a);
}
// For fonts the alpha information is stored in the red channel.
if (0x0u != (shaderFlags & 0x2u))
sampledColor = vec4(1.0, 1.0, 1.0, sampledColor.r);
@ -97,18 +109,6 @@ void main()
sampledColor *= opacity;
}
// Saturation.
if (saturation != 1.0) {
vec3 grayscale;
// Premultiplied textures are all in BGRA format.
if (0x0u != (shaderFlags & 0x01u))
grayscale = vec3(dot(sampledColor.bgr, vec3(0.34, 0.55, 0.11)));
else
grayscale = vec3(dot(sampledColor.rgb, vec3(0.34, 0.55, 0.11)));
vec3 blendedColor = mix(grayscale, sampledColor.rgb, saturation);
sampledColor = vec4(blendedColor, sampledColor.a);
}
// Dimming.
if (dimming != 1.0) {
vec4 dimColor = vec4(dimming, dimming, dimming, 1.0);