Created
June 24, 2015 16:32
-
-
Save cyberbobs/7884579521f561956d83 to your computer and use it in GitHub Desktop.
QML: recoloring fragment shader (recolor monochrome icons in runtime)
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
import QtQuick 2.4 | |
Item { | |
width: 320 | |
height: 640 | |
Image { | |
id: img | |
source: 'fingerprint.svg' | |
sourceSize.width: 320 | |
} | |
ShaderEffect { | |
id: shader | |
anchors.top: img.bottom | |
anchors.left: img.left | |
width: 320 | |
height: 320 | |
property variant source: img | |
property color color: "#4caf50" | |
fragmentShader: " | |
uniform lowp sampler2D source; | |
uniform highp vec4 color; | |
uniform lowp float qt_Opacity; | |
varying highp vec2 qt_TexCoord0; | |
void main() { | |
lowp vec4 tex = texture2D(source, qt_TexCoord0); | |
gl_FragColor = vec4(color.r, color.g, color.b, tex.a) * qt_Opacity; | |
} | |
" | |
} | |
SequentialAnimation | |
{ | |
running: true | |
loops: Animation.Infinite | |
ColorAnimation { | |
target: shader | |
property: "color" | |
to: "#b71c1c" | |
duration: 1000 | |
} | |
ColorAnimation { | |
target: shader | |
property: "color" | |
to: "#4caf50" | |
duration: 1000 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment