summaryrefslogtreecommitdiff
path: root/slideshow/opengl
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <emmanuel.peyrot@collabora.com>2015-12-09 21:39:35 +0000
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2015-12-11 15:29:01 +0100
commitd9116f2235e1a79c86446fc67231684edac49d82 (patch)
tree24786bfc6fcc83b66cd786d12efc7647104fe750 /slideshow/opengl
parentc0b8c035db9afd6271e0382c4f10ad44d3aa0dbb (diff)
slideshow: Improve the performances of the Glitter transition
Change-Id: Iaf482b357577ff8a5511607844a69c90ea28d29f
Diffstat (limited to 'slideshow/opengl')
-rw-r--r--slideshow/opengl/glitterFragmentShader.glsl36
-rw-r--r--slideshow/opengl/glitterVertexShader.glsl79
2 files changed, 115 insertions, 0 deletions
diff --git a/slideshow/opengl/glitterFragmentShader.glsl b/slideshow/opengl/glitterFragmentShader.glsl
new file mode 100644
index 000000000000..1bec20102be6
--- /dev/null
+++ b/slideshow/opengl/glitterFragmentShader.glsl
@@ -0,0 +1,36 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * 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/.
+ */
+
+#version 130
+
+#define M_PI 3.1415926535897932384626433832795
+
+uniform sampler2D leavingSlideTexture;
+uniform sampler2D enteringSlideTexture;
+varying vec2 v_texturePosition;
+varying vec3 v_normal;
+
+uniform float time;
+varying float angle;
+
+void main() {
+ vec3 lightVector = vec3(0.0, 0.0, 1.0);
+ float light = dot(lightVector, v_normal);
+
+ vec4 fragment;
+ if (angle < M_PI)
+ fragment = texture2D(leavingSlideTexture, v_texturePosition);
+ else
+ fragment = texture2D(enteringSlideTexture, v_texturePosition);
+
+ vec4 black = vec4(0.0, 0.0, 0.0, fragment.a);
+ gl_FragColor = mix(black, fragment, max(light, 0.0));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/slideshow/opengl/glitterVertexShader.glsl b/slideshow/opengl/glitterVertexShader.glsl
new file mode 100644
index 000000000000..9fdaf2999a14
--- /dev/null
+++ b/slideshow/opengl/glitterVertexShader.glsl
@@ -0,0 +1,79 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * 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/.
+ */
+
+#version 130
+
+#define M_PI 3.1415926535897932384626433832795
+
+attribute vec3 a_position;
+attribute vec3 a_normal;
+
+uniform mat4 u_projectionMatrix;
+uniform mat4 u_modelViewMatrix;
+uniform mat4 u_sceneTransformMatrix;
+uniform mat4 u_primitiveTransformMatrix;
+uniform mat4 u_operationsTransformMatrix;
+
+varying vec2 v_texturePosition;
+varying vec3 v_normal;
+
+attribute vec3 center;
+uniform float time;
+uniform ivec2 numTiles;
+uniform sampler2D permTexture;
+varying float angle;
+
+float snoise(vec2 p)
+{
+ return texture2D(permTexture, p).r;
+}
+
+mat4 translationMatrix(vec3 axis)
+{
+ 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,
+ axis.x, axis.y, axis.z, 1.0);
+}
+
+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 )
+{
+ // There are 18 vertices in an hexagon
+ int instanceID = gl_VertexID / 18;
+
+ vec2 pos = (center.xy + 1) / 2;
+ float fuzz = snoise(pos);
+ float startTime = pos.x * 0.5 + fuzz * 0.25;
+ float endTime = startTime + 0.25;
+ float actualTime = clamp((time - startTime) / (endTime - startTime), 0, 1);
+ angle = actualTime * M_PI * 2;
+
+ mat4 modelViewMatrix = u_modelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
+ mat4 transformMatrix = translationMatrix(center) * rotationMatrix(vec3(0, 1, 0), angle) * translationMatrix(-center);
+
+ mat3 normalMatrix = mat3(transpose(inverse(transformMatrix)));
+ gl_Position = u_projectionMatrix * modelViewMatrix * transformMatrix * vec4(a_position, 1.0);
+ v_texturePosition = vec2((a_position.x + 1) / 2, (1 - a_position.y) / 2);
+ v_normal = normalize(normalMatrix * a_normal);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */