Skip to content

Instantly share code, notes, and snippets.

@cyberbobs
Created June 24, 2015 16:32
Show Gist options
  • Save cyberbobs/7884579521f561956d83 to your computer and use it in GitHub Desktop.
Save cyberbobs/7884579521f561956d83 to your computer and use it in GitHub Desktop.
QML: recoloring fragment shader (recolor monochrome icons in runtime)
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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