Last active
June 18, 2019 16:13
-
-
Save a-andreyev/c52eb02eb408507445fa0e0c70b2e297 to your computer and use it in GitHub Desktop.
darkPaletteShader for Qt Telegram Chat discussion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SystemPalette { | |
id: defaultPalette | |
colorGroup: SystemPalette.Active | |
property color backgroundColor: defaultPalette.window | |
property bool backgroundColorIsDark: backgroundColor.hslLightness < 0.5 | |
|| backgroundColor.hslSaturation < -0.8 | |
} | |
ShaderEffect { | |
enabled: false | |
anchors.fill: img | |
property variant src: img | |
property alias backgroundColorIsDark: defaultPalette.backgroundColorIsDark | |
vertexShader: " | |
uniform highp mat4 qt_Matrix; | |
attribute highp vec4 qt_Vertex; | |
attribute highp vec2 qt_MultiTexCoord0; | |
varying highp vec2 coord; | |
void main() { | |
coord = qt_MultiTexCoord0; | |
gl_Position = qt_Matrix * qt_Vertex; | |
}" | |
fragmentShader: " | |
varying highp vec2 coord; | |
uniform sampler2D src; | |
uniform lowp float qt_Opacity; | |
uniform bool backgroundColorIsDark; | |
vec3 brightnessContrast(vec3 value, float brightness, float contrast) | |
{ | |
return value * contrast + brightness; | |
} | |
void main() { | |
lowp vec4 tex = texture2D(src, coord); | |
if (tex.r==float(102.0/255.0) && tex.g==float(72.0/255.0) && tex.b==float(72.0/255.0) && backgroundColorIsDark) | |
gl_FragColor = vec4(vec3(1.1-tex.r,1.1-tex.g,1.1-tex.b),tex.a) * qt_Opacity; | |
else | |
gl_FragColor = tex.rgba; | |
if (backgroundColorIsDark) { | |
gl_FragColor = vec4(brightnessContrast(gl_FragColor.rgb,-0.3,1.4),tex.a) * qt_Opacity; | |
} | |
}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment