summaryrefslogtreecommitdiff
path: root/slideshow/opengl
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <emmanuel.peyrot@collabora.com>2015-12-09 21:39:34 +0000
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2015-12-11 15:29:01 +0100
commitc0b8c035db9afd6271e0382c4f10ad44d3aa0dbb (patch)
treed7611926d0b405e2b7bd31f386450137202746a2 /slideshow/opengl
parentc5228bd0e430c3e45383939cdbd3e6dc7ee9dca6 (diff)
slideshow: Improve the performances of the Honeycomb transition
Change-Id: Iacddc7b84bf0be8bb112cba88cc7fd36f72e7ca0
Diffstat (limited to 'slideshow/opengl')
-rw-r--r--slideshow/opengl/honeycombFragmentShader.glsl63
-rw-r--r--slideshow/opengl/honeycombGeometryShader.glsl64
-rw-r--r--slideshow/opengl/honeycombVertexShader.glsl83
3 files changed, 210 insertions, 0 deletions
diff --git a/slideshow/opengl/honeycombFragmentShader.glsl b/slideshow/opengl/honeycombFragmentShader.glsl
new file mode 100644
index 000000000000..607e83d55a1c
--- /dev/null
+++ b/slideshow/opengl/honeycombFragmentShader.glsl
@@ -0,0 +1,63 @@
+/* -*- 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 150
+
+in vec2 texturePosition;
+in float fuzz;
+in vec2 v_center;
+
+uniform sampler2D slideTexture;
+uniform float selectedTexture;
+uniform float time;
+uniform float hexagonSize;
+
+bool isBorder(vec2 point)
+{
+ return point.x < 0.02 || point.x > 0.98 || point.y < 0.02 || point.y > 0.98;
+}
+
+void main()
+{
+ gl_FragColor = texture2D(slideTexture, texturePosition);
+ if (hexagonSize > 1.0) {
+ // The space in-between hexagons.
+ if (selectedTexture > 0.5)
+ gl_FragColor.a = 1.0 - time * 8 + gl_FragCoord.x / 1024.;
+ else
+ gl_FragColor.a = time * 8 - 7.7 + gl_FragCoord.x / 1024.;
+ } else {
+ // The hexagons themselves.
+
+ float startTime;
+ float actualTime;
+ if (selectedTexture > 0.5) {
+ // Leaving slide.
+ if (isBorder(v_center))
+ // If the center is “outside” of the canvas, clear it first.
+ startTime = 0.15;
+ else
+ startTime = 0.15 + fuzz * 0.3;
+ float endTime = startTime + 0.05;
+ actualTime = 1.0 - clamp((time - startTime) / (endTime - startTime), 0, 1);
+ } else {
+ // Entering slide.
+ if (isBorder(v_center))
+ // If the center is “outside” of the canvas, clear it first.
+ startTime = 0.85;
+ else
+ startTime = 0.5 + fuzz * 0.3;
+ float endTime = startTime + 0.05;
+ actualTime = clamp((time - startTime) / (endTime - startTime), 0, 1);
+ }
+ gl_FragColor.a = actualTime;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/slideshow/opengl/honeycombGeometryShader.glsl b/slideshow/opengl/honeycombGeometryShader.glsl
new file mode 100644
index 000000000000..bb2b1f3b3c78
--- /dev/null
+++ b/slideshow/opengl/honeycombGeometryShader.glsl
@@ -0,0 +1,64 @@
+/* -*- 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 150
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices=13) out;
+
+in mat4 modelViewProjectionMatrix[];
+
+uniform float hexagonSize;
+uniform sampler2D permTexture;
+
+out vec2 texturePosition;
+out float fuzz;
+out vec2 v_center;
+
+const float expandFactor = 0.0318;
+
+float snoise(vec2 p)
+{
+ return texture2D(permTexture, p).r;
+}
+
+void emitHexagonVertex(vec3 center, vec2 translation)
+{
+ vec4 pos = vec4(center + hexagonSize * expandFactor * vec3(translation, 0.0), 1.0);
+ gl_Position = modelViewProjectionMatrix[0] * pos;
+ texturePosition = vec2((pos.x + 1), (1 - pos.y)) / 2;
+ EmitVertex();
+}
+
+void main()
+{
+ vec2 translateVectors[6];
+ translateVectors[0] = vec2(-3, -2);
+ translateVectors[1] = vec2(0, -4);
+ translateVectors[2] = vec2(3, -2);
+ translateVectors[3] = vec2(3, 2);
+ translateVectors[4] = vec2(0, 4);
+ translateVectors[5] = vec2(-3, 2);
+
+ vec3 center = gl_in[0].gl_Position.xyz;
+
+ v_center = (1 + center.xy) / 2;
+ fuzz = snoise(center.xy);
+
+ emitHexagonVertex(center, translateVectors[5]);
+
+ for (int i = 0; i < 6; ++i) {
+ emitHexagonVertex(center, translateVectors[i]);
+ emitHexagonVertex(center, vec2(0, 0));
+ }
+
+ EndPrimitive();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/slideshow/opengl/honeycombVertexShader.glsl b/slideshow/opengl/honeycombVertexShader.glsl
new file mode 100644
index 000000000000..b54efbdb6ccf
--- /dev/null
+++ b/slideshow/opengl/honeycombVertexShader.glsl
@@ -0,0 +1,83 @@
+/* -*- 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 150
+
+#define M_PI 3.1415926535897932384626433832795
+
+in vec3 a_position;
+
+uniform mat4 u_projectionMatrix;
+uniform mat4 u_modelViewMatrix;
+uniform mat4 u_sceneTransformMatrix;
+uniform mat4 u_primitiveTransformMatrix;
+uniform mat4 u_operationsTransformMatrix;
+
+uniform float time;
+uniform float selectedTexture;
+
+out mat4 modelViewProjectionMatrix;
+
+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 scaleMatrix(vec3 axis)
+{
+ return mat4(axis.x, 0.0, 0.0, 0.0,
+ 0.0, axis.y, 0.0, 0.0,
+ 0.0, 0.0, axis.z, 0.0,
+ 0.0, 0.0, 0.0, 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 )
+{
+ mat4 modelViewMatrix = u_modelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
+ mat4 transformMatrix;
+
+ // TODO: use the aspect ratio of the slide instead.
+ mat4 slideScaleMatrix = scaleMatrix(vec3(0.75, 1, 1));
+ mat4 invertSlideScaleMatrix = scaleMatrix(1.0 / vec3(0.75, 1, 1));
+
+ if (selectedTexture > 0.5) {
+ // Leaving texture
+ transformMatrix = translationMatrix(vec3(0, 0, 6 * time))
+ * scaleMatrix(vec3(1 + pow(2 * time, 2.1), 1 + pow(2 * time, 2.1), 0))
+ * slideScaleMatrix
+ * rotationMatrix(vec3(0.0, 0.0, 1.0), -pow(time, 3) * M_PI)
+ * invertSlideScaleMatrix;
+ } else {
+ // Entering texture
+ transformMatrix = translationMatrix(vec3(0, 0, 28 * (sqrt(time) - 1)))
+ * slideScaleMatrix
+ * rotationMatrix(vec3(0.0, 0.0, 1.0), pow(time - 1, 2) * M_PI)
+ * invertSlideScaleMatrix;
+ }
+ modelViewProjectionMatrix = u_projectionMatrix * modelViewMatrix * transformMatrix;
+ gl_Position = vec4(a_position, 1.0);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */