1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
12 in vec2 texturePosition;
16 in vec4 shadowCoordinate;
18 uniform sampler2D slideTexture;
19 uniform sampler2D colorShadowTexture;
20 uniform sampler2D depthShadowTexture;
21 uniform float selectedTexture;
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;
32 const vec2 samplingPoints[9] = vec2[](
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.;
52 fragment.a = time * 8 - 7.3 + gl_FragCoord.x / 1024.;
54 // The hexagons themselves.
58 if (selectedTexture > 0.5) {
60 if (isBorder(v_center))
61 // If the center is “outside” of the canvas, clear it first.
64 startTime = 0.15 + fuzz * 0.4;
65 float endTime = startTime + 0.05;
66 actualTime = 1.0 - clamp((time - startTime) / (endTime - startTime), 0, 1);
69 if (isBorder(v_center))
70 // If the center is “outside” of the canvas, clear it first.
73 startTime = 0.3 + fuzz * 0.4;
74 float endTime = startTime + 0.05;
75 actualTime = clamp((time - startTime) / (endTime - startTime), 0, 1);
77 actualTime *= time / 0.8;
80 if (selectedTexture > 0.5) {
81 // Leaving texture needs to be transparent to see-through.
82 fragment.a = actualTime;
84 // Entering one though, would look weird with transparency.
85 fragment.rgb *= actualTime;
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;
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: */