tdf#124990: DnD operation can be set to fail in dropComplete
[LibreOffice.git] / slideshow / opengl / honeycombFragmentShader.glsl
blobe4ce8e31f91e8fae2b1f25b314fad60f69fcdee8
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
10 #version 150
12 in vec2 texturePosition;
13 in float fuzz;
14 in vec2 v_center;
15 in vec3 normal;
16 in vec4 shadowCoordinate;
18 uniform sampler2D slideTexture;
19 uniform sampler2D colorShadowTexture;
20 uniform sampler2D depthShadowTexture;
21 uniform float selectedTexture;
22 uniform float time;
23 uniform float hexagonSize;
25 bool isBorder(vec2 point)
27     return point.x < 0.02 || point.x > 0.98 || point.y < 0.02 || point.y > 0.98;
30 void main()
32     const vec2 samplingPoints[9] = vec2[](
33         vec2(0, 0),
34         vec2(-1, -1),
35         vec2(-1, 0),
36         vec2(-1, 1),
37         vec2(0, 1),
38         vec2(1, 1),
39         vec2(1, 0),
40         vec2(1, -1),
41         vec2(0, -1)
42     );
44     vec4 fragment = vec4(texture(slideTexture, texturePosition).rgb, 1.0);
45     vec3 lightVector = vec3(0.0, 0.0, 1.0);
46     float light = max(dot(lightVector, normal), 0.0);
47     if (hexagonSize > 1.0) {
48         // The space in-between hexagons.
49         if (selectedTexture > 0.5)
50             fragment.a = 1.0 - time * 8 + gl_FragCoord.x / 1024.;
51         else
52             fragment.a = time * 8 - 7.3 + gl_FragCoord.x / 1024.;
53     } else {
54         // The hexagons themselves.
56         float startTime;
57         float actualTime;
58         if (selectedTexture > 0.5) {
59             // Leaving slide.
60             if (isBorder(v_center))
61                 // If the center is “outside” of the canvas, clear it first.
62                 startTime = 0.15;
63             else
64                 startTime = 0.15 + fuzz * 0.4;
65             float endTime = startTime + 0.05;
66             actualTime = 1.0 - clamp((time - startTime) / (endTime - startTime), 0, 1);
67         } else {
68             // Entering slide.
69             if (isBorder(v_center))
70                 // If the center is “outside” of the canvas, clear it first.
71                 startTime = 0.85;
72             else
73                 startTime = 0.3 + fuzz * 0.4;
74             float endTime = startTime + 0.05;
75             actualTime = clamp((time - startTime) / (endTime - startTime), 0, 1);
76             if (time < 0.8)
77                 actualTime *= time / 0.8;
78         }
80         if (selectedTexture > 0.5) {
81             // Leaving texture needs to be transparent to see-through.
82             fragment.a = actualTime;
83         } else {
84             // Entering one though, would look weird with transparency.
85             fragment.rgb *= actualTime;
86         }
87     }
89     // Compute the shadow.
90     float visibility = 1.0;
91     const float epsilon = 0.0001;
92     if (selectedTexture < 0.5) {
93         float depthShadow = texture(depthShadowTexture, shadowCoordinate.xy).z;
94         float shadowRadius = (1.0 / (shadowCoordinate.z - depthShadow)) * 1000.0;
95         // Only the entering slide.
96         for (int i = 0; i < 9; ++i) {
97             vec2 coordinate = shadowCoordinate.xy + samplingPoints[i] / shadowRadius;
98             if (depthShadow < shadowCoordinate.z - epsilon) {
99                 visibility -= 0.05 * texture(colorShadowTexture, coordinate).a;
100             }
101         }
102     }
104     vec4 black = vec4(0.0, 0.0, 0.0, fragment.a);
105     gl_FragColor = mix(black, fragment, visibility * light);
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */