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 #define M_PI 3.1415926535897932384626433832795
19 uniform mat4 u_modelViewMatrix;
20 uniform mat4 u_sceneTransformMatrix;
21 uniform mat4 u_primitiveTransformMatrix;
22 uniform mat4 u_operationsTransformMatrix;
25 uniform ivec2 numTiles;
26 uniform sampler2D permTexture;
29 // Workaround for Intel's Windows driver, to prevent optimisation breakage.
32 out vec2 g_texturePosition;
34 out mat4 modelViewMatrix;
42 return texture(permTexture, p).r;
45 mat4 identityMatrix(void)
47 return mat4(1.0, 0.0, 0.0, 0.0,
53 mat4 translationMatrix(vec3 axis)
55 mat4 matrix = identityMatrix();
56 matrix[3] = vec4(axis, 1.0);
60 mat4 rotationMatrix(vec3 axis, float angle)
62 axis = normalize(axis);
67 return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
68 oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
69 oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
75 // Each tile moves during only half of the transition. The leftmost
76 // tiles start moving at the start and arrive at their end
77 // position around time=0.5, when the tiles there (the rightmost
78 // ones) start moving. (The exact time each tile is moving is
79 // fuzzed a bit to make a more random appearance.)
81 // In GLSL 1.20 we don't have any bitwise operators, sigh
83 int tileXIndex = int(mod(int(tileInfo), 256));
84 int tileYIndex = int(mod(int(tileInfo) / 256, 256));
86 // A semi-random number 0..1, different for neighbouring tiles, to know when they should start moving.
87 float startTimeFuzz = snoise(vec2(float(tileXIndex)/(numTiles.x-1), float(tileYIndex)/(numTiles.y-1)));
89 // A semi-random number -1.5..1.5, different for neighbouring tiles, to specify their rotation center.
90 // The additional 0.5 on each side is because we want some tiles to rotate outside.
91 float rotationFuzz = snoise(vec2(float(numTiles.x + tileXIndex)/(numTiles.x-1), float(tileYIndex)/(numTiles.y-1))) * 3.0 - 1.5;
93 startTime = float(tileXIndex)/(numTiles.x-1) * 0.2 + startTimeFuzz * 0.2;
94 endTime = min(startTime + 0.7, 1.0);
96 bool isLeavingSlide = (slide < 0.5);
97 const vec4 invalidPosition = vec4(-256.0, -256.0, -256.0, -256.0);
99 // Don’t display the tile before or after its rotation, depending on the slide.
102 if (time < max(0.3, startTime))
104 gl_Position = invalidPosition;
113 gl_Position = invalidPosition;
119 transform = identityMatrix();
120 if (nTime > startTime && nTime <= endTime)
122 // We are in the rotation part.
123 float rotation = (nTime - startTime) / (endTime - startTime);
127 if (rotation < -0.5 || rotation > 0.5) {
128 gl_Position = invalidPosition;
132 // Translation vector to set the origin of the rotation.
133 vec3 translationVector = vec3(rotationFuzz, 0.0, 0.0);
135 // Compute the actual rotation matrix.
137 // Intel's Windows driver gives a wrong matrix when all operations are done at once.
139 transform = translationMatrix(translationVector) * transform;
141 transform = rotationMatrix(vec3(0.0, 1.0, 0.0), clamp(rotation, -1.0, 1.0) * M_PI) * transform;
143 transform = translationMatrix(-translationVector) * transform;
146 modelViewMatrix = u_modelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
147 gl_Position = vec4(a_position, 1.0);
149 g_texturePosition = a_texCoord;
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */