-
Notifications
You must be signed in to change notification settings - Fork 1
/
Vignette.qml
82 lines (69 loc) · 2.44 KB
/
Vignette.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/****************************************************************************
* This file is part of Fluid.
*
* Copyright (C) 2013-2016 Pier Luigi Fiorini
*
* Author(s):
* Pier Luigi Fiorini <[email protected]>
*
* $BEGIN_LICENSE:LGPL2.1+$
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* $END_LICENSE$
***************************************************************************/
import QtQuick 2.0
Item {
id: root
/*!
This property defines the source item that is going to be used as source
for the generated effect.
*/
property variant source
/*!
This property defines the vignette radius.
*/
property alias radius: effect.radius
/*!
This property defines how much brightness will be used.
*/
property alias brightness: effect.brightness
ShaderEffect {
id: effect
anchors.fill: parent
property variant source: ShaderEffectSource {
sourceItem: root.source
sourceRect: Qt.rect(0, 0, 0, 0)
hideSource: false
smooth: true
visible: false
}
property real radius: 16
property real brightness: 0.1
fragmentShader: "
varying highp vec2 qt_TexCoord0;
uniform highp float qt_Opacity;
uniform highp float radius;
uniform highp float brightness;
uniform lowp sampler2D source;
void main() {
highp vec2 uv = qt_TexCoord0.xy;
highp vec2 coord = qt_TexCoord0 - 0.5;
lowp vec4 orig = texture2D(source, uv);
highp float vignette = 1.0 - dot(coord, coord);
lowp vec3 col = orig.rgb * clamp(pow(vignette, radius) + brightness, 0.0, 1.0);
gl_FragColor = vec4(col, 1.0);
}"
}
}