[vlc-commits] qml: add FrostedGlassEffect.qml

Fatih Uzunoglu git at videolan.org
Thu Aug 27 12:44:49 CEST 2020


vlc | branch: master | Fatih Uzunoglu <fuzun54 at outlook.com> | Mon Aug 10 16:41:18 2020 +0300| [f65542b49e5933097190600f8308db00ba81b8f0] | committer: Pierre Lamot

qml: add FrostedGlassEffect.qml

Co-authored-by: Pierre Lamot <pierre at videolabs.io>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f65542b49e5933097190600f8308db00ba81b8f0
---

 modules/gui/qt/Makefile.am                        |   3 +-
 modules/gui/qt/vlc.qrc                            |   1 +
 modules/gui/qt/widgets/qml/FrostedGlassEffect.qml | 111 ++++++++++++++++++++++
 3 files changed, 114 insertions(+), 1 deletion(-)

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index 9a8f5fab26..e718bdf3fe 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -706,7 +706,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 df2c7bbef7..97aa678d7d 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -223,6 +223,7 @@
         <file alias="MenuLabel.qml">widgets/qml/MenuLabel.qml</file>
         <file alias="ListSubtitleLabel.qml">widgets/qml/ListSubtitleLabel.qml</file>
         <file alias="HorizontalResizeHandle.qml">widgets/qml/HorizontalResizeHandle.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;
+                    }"
+            }
+        }
+    }
+}



More information about the vlc-commits mailing list