[vlc-devel] [PATCH 19/38] qml: add FrostedGlassEffect.qml

Fatih Uzunoglu fuzun54 at outlook.com
Thu Aug 20 19:55:28 CEST 2020


Co-authored-by: Pierre Lamot <pierre at videolabs.io>
---
 modules/gui/qt/Makefile.am                    |   3 +-
 modules/gui/qt/vlc.qrc                        |   1 +
 .../gui/qt/widgets/qml/FrostedGlassEffect.qml | 111 ++++++++++++++++++
 3 files changed, 114 insertions(+), 1 deletion(-)
 create mode 100644 modules/gui/qt/widgets/qml/FrostedGlassEffect.qml

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 90e3efacde..01b753e9a8 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -695,7 +695,8 @@ libqt_plugin_la_QML = \
 	gui/qt/widgets/qml/ToolTipArea.qml \
 	gui/qt/widgets/qml/VideoProgressBar.qml \
 	gui/qt/widgets/qml/VideoQualityLabel.qml \
-	gui/qt/widgets/qml/ListSubtitleLabel.qml
+	gui/qt/widgets/qml/ListSubtitleLabel.qml \
+	gui/qt/widgets/qml/FrostedGlassEffect.qml
 
 EXTRA_DIST += gui/qt/vlc.qrc $(libqt_plugin_la_RES)
 
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index b545e1b8dd..ac16912949 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -221,6 +221,7 @@
         <file alias="MediaCover.qml">widgets/qml/MediaCover.qml</file>
         <file alias="MenuLabel.qml">widgets/qml/MenuLabel.qml</file>
         <file alias="ListSubtitleLabel.qml">widgets/qml/ListSubtitleLabel.qml</file>
+        <file alias="FrostedGlassEffect.qml">widgets/qml/FrostedGlassEffect.qml</file>
     </qresource>
     <qresource prefix="/util">
         <file alias="SelectableDelegateModel.qml">util/qml/SelectableDelegateModel.qml</file>
diff --git a/modules/gui/qt/widgets/qml/FrostedGlassEffect.qml b/modules/gui/qt/widgets/qml/FrostedGlassEffect.qml
new file mode 100644
index 0000000000..d390825679
--- /dev/null
+++ b/modules/gui/qt/widgets/qml/FrostedGlassEffect.qml
@@ -0,0 +1,111 @@
+/*****************************************************************************
+ * Copyright (C) 2020 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+import QtQuick 2.11
+import QtGraphicalEffects 1.0
+
+import "qrc:///style/"
+
+Rectangle {
+    id: effect
+
+    property variant source
+    property variant sourceRect: undefined
+
+    property bool active: true
+
+    color: tint
+
+    property color tint: VLCStyle.colors.banner
+    property real tintStrength: 0.7
+    property real noiseStrength: 0.02
+    property real exclusionStrength: 0.09
+
+    Item {
+        anchors.fill: parent
+
+        layer.enabled: effect.active
+        layer.effect: Item {
+
+            FastBlur {
+                id: effect1
+                anchors.fill: parent
+
+                source: ShaderEffectSource {
+                    sourceItem: effect.source
+                    sourceRect: !!effect.sourceRect ? effect.sourceRect : effect.mapToItem(effect.source, Qt.rect(effect.x, effect.y, effect.width, effect.height))
+                    visible: false
+                }
+
+                radius: 64
+                visible: false
+            }
+
+            ShaderEffect {
+                id: effect2
+
+                property variant source: ShaderEffectSource {
+                    sourceItem: effect1
+                    visible: true
+                }
+
+                anchors.fill: parent
+
+                visible: true
+
+                property color tint: effect.tint
+                property real  tintStrength: effect.tintStrength
+                property real  noiseStrength: effect.noiseStrength
+                property real  exclusionStrength: effect.exclusionStrength
+
+                fragmentShader: "
+                    uniform lowp sampler2D source; // this item
+                    varying highp vec2 qt_TexCoord0;
+
+                    uniform lowp vec4  tint;
+
+                    uniform lowp float exclusionStrength;
+                    uniform lowp float noiseStrength;
+                    uniform lowp float tintStrength;
+
+
+                    float rand(vec2 co){
+                        return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
+                    }
+
+
+                    vec4 exclude(vec4 src, vec4 dst)
+                    {
+                        return src + dst - 2.0 * src * dst;
+                    }
+
+                    void main() {
+                       float r = rand(qt_TexCoord0) - 0.5;
+                       vec4 noise = vec4(r,r,r,1.0) * noiseStrength;
+                       vec4 blured  = texture2D(source, qt_TexCoord0);
+
+                       vec4 exclColor = vec4(exclusionStrength, exclusionStrength, exclusionStrength, 0.0);
+
+                       blured = exclude(blured, exclColor);
+
+                       gl_FragColor = mix(blured, tint, tintStrength) + noise;
+                    }"
+            }
+        }
+    }
+}
-- 
2.25.1



More information about the vlc-devel mailing list