Created
December 21, 2023 16:14
-
-
Save patrickelectric/1e57310d31b77dc241789bbd601aa54f to your computer and use it in GitHub Desktop.
Do edge filtering in qml
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.7 | |
import QtQuick.Controls 2.3 | |
Rectangle { | |
color: "red" | |
anchors.fill: parent | |
AnimatedImage { | |
id: oldFrame | |
source: "https://cdn.pixabay.com/animation/2022/10/11/09/05/09-05-26-529_512.gif" | |
visible: false | |
currentFrame: profilePic.currentFrame - 2 | |
} | |
ShaderEffect { | |
AnimatedImage { | |
id: profilePic | |
source: "https://cdn.pixabay.com/animation/2022/10/11/09/05/09-05-26-529_512.gif" | |
visible: false | |
} | |
property variant src: profilePic | |
property variant old: oldFrame | |
width: 400 | |
height: width | |
anchors.centerIn: parent | |
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: " | |
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
varying highp vec2 coord; | |
uniform sampler2D src; | |
uniform sampler2D old; | |
uniform lowp float qt_Opacity; | |
void main() { | |
float d = distance(coord, vec2(0.5, 0.5)); | |
if(d > 0.5) { | |
gl_FragColor = vec4(0, 0, 0, 0) * qt_Opacity; | |
return; | |
} | |
lowp vec4 tex = texture2D(src, coord); | |
lowp vec4 oldTex = texture2D(old, coord); | |
gl_FragColor = vec4(tex.rgb - oldTex.rgb, tex.a) * qt_Opacity; | |
} | |
" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment