Skip to content

Instantly share code, notes, and snippets.

@kovrov
Created July 22, 2014 07:21
Show Gist options
  • Save kovrov/559e10959b98c51d9fd3 to your computer and use it in GitHub Desktop.
Save kovrov/559e10959b98c51d9fd3 to your computer and use it in GitHub Desktop.
SpinnerEffect.qml
import QtQuick 2.2
import QtQuick.Window 2.2
Window {
color: "gray"
NumberAnimation {
target: fx
property: "angle"; from: Math.PI * 2; to: 0
loops: Animation.Infinite
running: true
duration: 2000
}
ShaderEffect {
id: fx
anchors.centerIn: parent
width: 64
height: 64
property real angle
property var mask: Image {
sourceSize: Qt.size(fx.width, fx.height)
source: "squircle.svg"
}
property var background: ShaderEffectSource {
id: fbo
live: false
sourceItem: Canvas {
width: fx.width
height: fx.height
onPaint: {
var ctx = getContext('2d');
ctx.reset();
var gradient = ctx.createConicalGradient(width / 2, width / 2, 0);
gradient.addColorStop(0, "#fff");
gradient.addColorStop(1, "#00000000");
ctx.fillStyle = gradient
ctx.fillRect(0,0, width, height);
fbo.scheduleUpdate();
}
}
}
fragmentShader: "#version 120
varying highp vec2 qt_TexCoord0;
uniform lowp float qt_Opacity;
uniform sampler2D mask;
uniform sampler2D background;
uniform float angle;
void main() {
mat4 transf = mat4(1.0, 0.0, 0.0, -0.5,
0.0, 1.0, 0.0, -0.5,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0)
* mat4(cos(angle), -sin(angle), 0.0, 0.0,
sin(angle), cos(angle), 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0)
* mat4(1.0, 0.0, 0.0, 0.5,
0.0, 1.0, 0.0, 0.5,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
vec4 coord = vec4(qt_TexCoord0, 0, 1) * transf;
vec4 color_tex = texture2D(background, coord.st);
vec4 mask_tex = texture2D(mask, qt_TexCoord0.st);
color_tex.a *= mask_tex.a;
gl_FragColor = color_tex * mask_tex.a * qt_Opacity;
}"
}
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment