2d64c2ae76b584ddd8daf14a2379aa43e93d6f24
[staging/HomeScreen.git] / sample-qml / imports / components / InShadow.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: 16
13
14     fragmentShader: "
15 uniform lowp float radius;
16 uniform lowp float height;
17 uniform lowp float width;
18 uniform lowp float qt_Opacity;
19 uniform lowp vec4 color;
20 varying highp vec2 qt_TexCoord0;
21
22 void main(void) {
23     lowp vec2 dist = min(qt_TexCoord0, vec2(1.0) - qt_TexCoord0);
24     // Border shadow
25     lowp float xval = smoothstep(0.0, radius, dist.x * width);
26     lowp float yval = smoothstep(0.0, radius, dist.y * height);
27     lowp float borderVal = sqrt(yval * xval) * 0.5 + 0.5;
28
29     lowp vec4 borderColor = mix(color, vec4(0.0, 0.0, 0.0, 1.0), borderVal);
30     gl_FragColor = borderColor * qt_Opacity;
31 }
32     "
33 }