on 6ca9421 help sign in
unity8/qml/Components/BlurLayer.qml
69 lines 2.2 kB history raw
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.4
18import QtGraphicalEffects 1.0
20Item {
21 id: root
23 property alias source: shaderEffectSource.sourceItem
24 property alias saturation: desaturateEffect.saturationValue
25 property alias blurRadius: fastBlur.radius
27 readonly property alias ready: shaderEffectSource.ready
29 ShaderEffect {
30 id: desaturateEffect
31 anchors.fill: root
33 property real saturationValue: 1
35 property variant source: ShaderEffectSource {
36 id: shaderEffectSource
37 hideSource: root.visible
38 live: !root.visible
39 property bool ready: false;
40 onLiveChanged: {
41 if (!live) {
42 ready = false;
43 scheduleUpdate();
44 }
45 }
46 onScheduledUpdateCompleted: ready = true;
47 }
49 fragmentShader: "
50 varying highp vec2 qt_TexCoord0;
51 uniform sampler2D source;
52 uniform lowp float saturationValue;
53 void main(void)
54 {
55 highp vec4 sourceColor = texture2D(source, qt_TexCoord0);
56 highp vec4 scaledColor = sourceColor * vec4(0.3, 0.59, 0.11, 1.0);
57 lowp float luminance = scaledColor.r + scaledColor.g + scaledColor.b ;
58 gl_FragColor = mix(vec4(luminance, luminance, luminance, sourceColor.a), sourceColor, saturationValue);
59 }"
60 }
62 FastBlur {
63 id: fastBlur
64 anchors.fill: parent
65 source: desaturateEffect
66 visible: radius > 0
67 radius: 0
68 }