From 0ad339d4c4d5e50971bd9a614cd774dc2b8a81f0 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 12 Dec 2022 20:21:22 +0100 Subject: [PATCH] Fixed an issue where lowered saturation could not be combined with color shifts. --- resources/shaders/glsl/core.glsl | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/resources/shaders/glsl/core.glsl b/resources/shaders/glsl/core.glsl index 22fb53cfc..2bcd22374 100644 --- a/resources/shaders/glsl/core.glsl +++ b/resources/shaders/glsl/core.glsl @@ -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);