Add sample qml application
[staging/HomeScreen.git] / sample-qml / imports / components / InsetShadow.qml
1 /* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved.
2  *
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 import QtQuick 2.0    
8
9 ShaderEffect {
10     anchors.fill: parent
11     property color color
12     property real radius: 100
13     property real border: 20
14
15     fragmentShader: "
16 uniform lowp float radius;
17 uniform lowp float border;
18 uniform lowp float height;
19 uniform lowp float width;
20 uniform lowp float qt_Opacity;
21 uniform lowp vec4 color;
22 varying highp vec2 qt_TexCoord0;
23
24 void main(void) {
25     lowp vec2 dist = min(qt_TexCoord0, vec2(1.0) - qt_TexCoord0);
26     // Border shadow
27     lowp float xval = smoothstep(0.0, border, dist.x * width);
28     lowp float yval = smoothstep(0.0, border, dist.y * height);
29     lowp float borderVal = sqrt(yval * xval) * 0.5 + 0.5;
30     // Inner shadow
31     xval = smoothstep(0.0, radius, dist.x * width);
32     yval = smoothstep(0.0, radius, dist.y * width);
33     lowp float innerVal = sqrt(yval * xval) * 0.5 + 0.5;
34
35     lowp vec4 innerColor = mix(vec4(0.0, 0.0, 0.0, 0.5), color, innerVal);
36     lowp vec4 borderColor = mix(vec4(0.0, 0.0, 0.0, 1.0), innerColor, borderVal);
37     gl_FragColor = borderColor * qt_Opacity;
38 }
39     "
40 }