2015-10-26 17:05:38 +02:00
|
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2015-10-27 14:46:45 +02:00
|
|
|
|
/*
|
|
|
|
|
* This file is part of the LibreOffice project.
|
2015-10-26 17:05:38 +02:00
|
|
|
|
*
|
2015-10-27 14:46:45 +02:00
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2015-10-26 17:05:38 +02:00
|
|
|
|
|
2016-01-20 21:04:37 +00:00
|
|
|
|
#version 150
|
2015-11-07 00:37:21 +02:00
|
|
|
|
|
2015-10-26 17:05:38 +02:00
|
|
|
|
#define M_PI 3.1415926535897932384626433832795
|
|
|
|
|
|
2016-01-20 21:04:37 +00:00
|
|
|
|
in vec3 a_position;
|
|
|
|
|
in vec3 a_normal;
|
|
|
|
|
in vec2 a_texCoord;
|
|
|
|
|
in float tileInfo;
|
2015-12-09 21:39:26 +00:00
|
|
|
|
|
|
|
|
|
uniform mat4 u_modelViewMatrix;
|
|
|
|
|
uniform mat4 u_sceneTransformMatrix;
|
|
|
|
|
uniform mat4 u_primitiveTransformMatrix;
|
|
|
|
|
uniform mat4 u_operationsTransformMatrix;
|
|
|
|
|
|
2015-10-26 17:05:38 +02:00
|
|
|
|
uniform float time;
|
2015-11-06 17:44:52 +02:00
|
|
|
|
uniform ivec2 numTiles;
|
2015-10-26 17:05:38 +02:00
|
|
|
|
uniform sampler2D permTexture;
|
2015-12-21 21:25:34 +00:00
|
|
|
|
uniform float slide;
|
|
|
|
|
|
2016-02-24 20:21:12 +00:00
|
|
|
|
// Workaround for Intel's Windows driver, to prevent optimisation breakage.
|
|
|
|
|
uniform float zero;
|
|
|
|
|
|
2016-01-20 21:04:37 +00:00
|
|
|
|
out vec2 g_texturePosition;
|
|
|
|
|
out vec3 g_normal;
|
|
|
|
|
out mat4 modelViewMatrix;
|
|
|
|
|
out mat4 transform;
|
|
|
|
|
out float nTime;
|
|
|
|
|
out float startTime;
|
|
|
|
|
out float endTime;
|
2015-12-21 21:25:35 +00:00
|
|
|
|
|
2015-10-26 17:05:38 +02:00
|
|
|
|
float snoise(vec2 p)
|
|
|
|
|
{
|
2016-02-24 20:21:10 +00:00
|
|
|
|
return texture(permTexture, p).r;
|
2015-10-26 17:05:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-21 21:25:34 +00:00
|
|
|
|
mat4 identityMatrix(void)
|
|
|
|
|
{
|
|
|
|
|
return mat4(1.0, 0.0, 0.0, 0.0,
|
|
|
|
|
0.0, 1.0, 0.0, 0.0,
|
|
|
|
|
0.0, 0.0, 1.0, 0.0,
|
|
|
|
|
0.0, 0.0, 0.0, 1.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mat4 translationMatrix(vec3 axis)
|
|
|
|
|
{
|
|
|
|
|
mat4 matrix = identityMatrix();
|
|
|
|
|
matrix[3] = vec4(axis, 1.0);
|
|
|
|
|
return matrix;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-26 17:05:38 +02:00
|
|
|
|
mat4 rotationMatrix(vec3 axis, float angle)
|
|
|
|
|
{
|
|
|
|
|
axis = normalize(axis);
|
|
|
|
|
float s = sin(angle);
|
|
|
|
|
float c = cos(angle);
|
|
|
|
|
float oc = 1.0 - c;
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
|
|
|
|
|
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
|
|
|
|
|
0.0, 0.0, 0.0, 1.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void main( void )
|
|
|
|
|
{
|
2016-01-05 17:59:50 +01:00
|
|
|
|
// Each tile moves during only half of the transition. The leftmost
|
2015-11-09 09:04:41 +02:00
|
|
|
|
// tiles start moving at the start and arrive at their end
|
|
|
|
|
// position around time=0.5, when the tiles there (the rightmost
|
|
|
|
|
// ones) start moving. (The exact time each tile is moving is
|
|
|
|
|
// fuzzed a bit to make a more random appearance.)
|
2015-11-06 17:44:52 +02:00
|
|
|
|
|
2015-11-07 00:37:21 +02:00
|
|
|
|
// In GLSL 1.20 we don't have any bitwise operators, sigh
|
|
|
|
|
|
|
|
|
|
int tileXIndex = int(mod(int(tileInfo), 256));
|
|
|
|
|
int tileYIndex = int(mod(int(tileInfo) / 256, 256));
|
|
|
|
|
|
2015-12-21 21:25:34 +00:00
|
|
|
|
// A semi-random number 0..1, different for neighbouring tiles, to know when they should start moving.
|
|
|
|
|
float startTimeFuzz = snoise(vec2(float(tileXIndex)/(numTiles.x-1), float(tileYIndex)/(numTiles.y-1)));
|
2015-11-06 17:44:52 +02:00
|
|
|
|
|
2015-12-21 21:25:34 +00:00
|
|
|
|
// A semi-random number -1.5..1.5, different for neighbouring tiles, to specify their rotation center.
|
|
|
|
|
// The additional 0.5 on each side is because we want some tiles to rotate outside.
|
|
|
|
|
float rotationFuzz = snoise(vec2(float(numTiles.x + tileXIndex)/(numTiles.x-1), float(tileYIndex)/(numTiles.y-1))) * 3.0 - 1.5;
|
2015-11-10 10:48:24 +02:00
|
|
|
|
|
2016-01-20 21:04:37 +00:00
|
|
|
|
startTime = float(tileXIndex)/(numTiles.x-1) * 0.2 + startTimeFuzz * 0.2;
|
|
|
|
|
endTime = min(startTime + 0.7, 1.0);
|
2015-11-07 00:37:21 +02:00
|
|
|
|
|
2015-12-21 21:25:34 +00:00
|
|
|
|
bool isLeavingSlide = (slide < 0.5);
|
|
|
|
|
const vec4 invalidPosition = vec4(-256.0, -256.0, -256.0, -256.0);
|
2015-11-10 10:48:24 +02:00
|
|
|
|
|
2015-12-21 21:25:34 +00:00
|
|
|
|
// Don’t display the tile before or after its rotation, depending on the slide.
|
|
|
|
|
if (!isLeavingSlide)
|
|
|
|
|
{
|
|
|
|
|
if (time < max(0.3, startTime))
|
|
|
|
|
{
|
|
|
|
|
gl_Position = invalidPosition;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
nTime = 1.0 - time;
|
2015-11-06 17:44:52 +02:00
|
|
|
|
}
|
2015-10-26 17:05:38 +02:00
|
|
|
|
else
|
2015-11-06 17:44:52 +02:00
|
|
|
|
{
|
2015-12-21 21:25:34 +00:00
|
|
|
|
if (time > endTime)
|
|
|
|
|
{
|
|
|
|
|
gl_Position = invalidPosition;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
nTime = time;
|
|
|
|
|
}
|
2015-10-26 17:05:38 +02:00
|
|
|
|
|
2016-01-20 21:04:37 +00:00
|
|
|
|
transform = identityMatrix();
|
2015-12-21 21:25:34 +00:00
|
|
|
|
if (nTime > startTime && nTime <= endTime)
|
|
|
|
|
{
|
|
|
|
|
// We are in the rotation part.
|
2016-01-20 21:04:37 +00:00
|
|
|
|
float rotation = (nTime - startTime) / (endTime - startTime);
|
|
|
|
|
if (isLeavingSlide)
|
|
|
|
|
rotation *= -1.0;
|
|
|
|
|
|
|
|
|
|
if (rotation < -0.5 || rotation > 0.5) {
|
|
|
|
|
gl_Position = invalidPosition;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-12-21 21:25:34 +00:00
|
|
|
|
|
|
|
|
|
// Translation vector to set the origin of the rotation.
|
|
|
|
|
vec3 translationVector = vec3(rotationFuzz, 0.0, 0.0);
|
|
|
|
|
|
|
|
|
|
// Compute the actual rotation matrix.
|
2016-02-24 20:21:12 +00:00
|
|
|
|
|
|
|
|
|
// Intel's Windows driver gives a wrong matrix when all operations are done at once.
|
|
|
|
|
if (zero < 1.0)
|
|
|
|
|
transform = translationMatrix(translationVector) * transform;
|
|
|
|
|
if (zero < 2.0)
|
|
|
|
|
transform = rotationMatrix(vec3(0.0, 1.0, 0.0), clamp(rotation, -1.0, 1.0) * M_PI) * transform;
|
|
|
|
|
if (zero < 3.0)
|
|
|
|
|
transform = translationMatrix(-translationVector) * transform;
|
2016-02-09 09:27:47 +00:00
|
|
|
|
}
|
2015-12-21 21:25:34 +00:00
|
|
|
|
|
2016-01-20 21:04:37 +00:00
|
|
|
|
modelViewMatrix = u_modelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
|
|
|
|
|
gl_Position = vec4(a_position, 1.0);
|
2015-10-26 17:05:38 +02:00
|
|
|
|
|
2016-01-20 21:04:37 +00:00
|
|
|
|
g_texturePosition = a_texCoord;
|
|
|
|
|
g_normal = a_normal;
|
2015-10-26 17:05:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|