Debian Codegraph @

src/LomiriToolkit/privates/shaders/frame.frag

raw
1 /*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Loïc Molinari <[email protected]>
17 */
18
19 #version 440
20
21 layout(location = 0) in vec2 outerCoord;
22 layout(location = 1) in vec2 innerCoord;
23 layout(location = 2) in vec4 color;
24
25 layout(location = 0) out vec4 fragColor;
26
27 layout(std140, binding = 0) uniform buf {
28 mat4 qt_Matrix;
29 float qt_Opacity;
30 } ubuf;
31
32 layout(binding = 1) uniform sampler2D sourceTexture;
33
34 void main(void)
35 {
36 float shapeOut = texture(sourceTexture, outerCoord).r;
37 float shapeIn = texture(sourceTexture, innerCoord).r;
38 // Fused multiply-add friendly version of (shapeOut * (1.0 - shapeIn))
39 float shape = (shapeOut * -shapeIn) + shapeOut;
40 // shape is squared to make thinner corners (particularly visible at stroke 1).
41 fragColor = vec4(shape * shape * ubuf.qt_Opacity) * color;
42 }