summaryrefslogtreecommitdiff
path: root/slideshow/opengl
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <emmanuel.peyrot@collabora.com>2016-02-09 09:27:47 +0000
committerMichael Meeks <michael.meeks@collabora.com>2016-02-09 17:02:46 +0000
commit0c14c7babb71588fd93c1adccf4a99bf1b65dbd3 (patch)
tree9b6dbc38f7df6f9afe361d9f3fa4dfe543b5d803 /slideshow/opengl
parent882d27fce20ee0537f785a619be1dd065ea6bbca (diff)
slideshow: Add shadows to the Vortex transition
These are done using a shadow mapping technique, we render both slides from the point of view of the light, and then do a second pass in which we lower the light of the fragment if some other cube is above it. Change-Id: I8aaa1428c4481661283bf69b5e56aa4d95fb80dd Reviewed-on: https://gerrit.libreoffice.org/22232 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'slideshow/opengl')
-rw-r--r--slideshow/opengl/vortexFragmentShader.glsl34
-rw-r--r--slideshow/opengl/vortexGeometryShader.glsl32
-rw-r--r--slideshow/opengl/vortexVertexShader.glsl19
3 files changed, 76 insertions, 9 deletions
diff --git a/slideshow/opengl/vortexFragmentShader.glsl b/slideshow/opengl/vortexFragmentShader.glsl
new file mode 100644
index 000000000000..3212ebef7661
--- /dev/null
+++ b/slideshow/opengl/vortexFragmentShader.glsl
@@ -0,0 +1,34 @@
+/* -*- 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
+
+uniform sampler2D slideTexture;
+uniform sampler2D leavingShadowTexture;
+uniform sampler2D enteringShadowTexture;
+
+in vec2 v_texturePosition;
+in vec3 v_normal;
+in vec4 shadowCoordinate;
+
+void main() {
+ vec3 lightVector = vec3(0.0, 0.0, 1.0);
+ float light = max(dot(lightVector, v_normal), 0.0);
+ vec4 fragment = texture2D(slideTexture, v_texturePosition);
+ float visibility = 1.0;
+ const float epsilon = 0.0001;
+ if (texture2D(leavingShadowTexture, shadowCoordinate.xy).r < shadowCoordinate.z - epsilon)
+ visibility *= 0.7;
+ if (texture2D(enteringShadowTexture, shadowCoordinate.xy).r < shadowCoordinate.z - epsilon)
+ visibility *= 0.7;
+ vec4 black = vec4(0.0, 0.0, 0.0, fragment.a);
+ gl_FragColor = mix(black, fragment, visibility * light);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/slideshow/opengl/vortexGeometryShader.glsl b/slideshow/opengl/vortexGeometryShader.glsl
index 46999efad55f..312babac1c2f 100644
--- a/slideshow/opengl/vortexGeometryShader.glsl
+++ b/slideshow/opengl/vortexGeometryShader.glsl
@@ -14,16 +14,41 @@ layout(triangle_strip, max_vertices=11) out;
in vec2 g_texturePosition[];
in vec3 g_normal[];
+in mat4 projectionMatrix[];
in mat4 modelViewMatrix[];
+in mat4 shadowMatrix[];
in mat4 transform[];
in float nTime[];
in float startTime[];
in float endTime[];
-uniform mat4 u_projectionMatrix;
-
out vec2 v_texturePosition;
out vec3 v_normal;
+out vec4 shadowCoordinate;
+
+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 scaleMatrix(vec3 axis)
+{
+ mat4 matrix = identityMatrix();
+ matrix[0][0] = axis.x;
+ matrix[1][1] = axis.y;
+ matrix[2][2] = axis.z;
+ return matrix;
+}
+
+mat4 translationMatrix(vec3 axis)
+{
+ mat4 matrix = identityMatrix();
+ matrix[3] = vec4(axis, 1.0);
+ return matrix;
+}
void emitHexagonVertex(int index, vec3 translation, float fdsq)
{
@@ -37,7 +62,8 @@ void emitHexagonVertex(int index, vec3 translation, float fdsq)
v_normal = normalize(vec3(normalMatrix * transform[index] * vec4(g_normal[index], 0.0)));
v_normal.z *= fdsq;
- gl_Position = u_projectionMatrix * modelViewMatrix[index] * pos;
+ gl_Position = projectionMatrix[index] * modelViewMatrix[index] * pos;
+ shadowCoordinate = translationMatrix(vec3(0.5, 0.5, 0.5)) * scaleMatrix(vec3(0.5, 0.5, 0.5)) * shadowMatrix[index] * modelViewMatrix[index] * pos;
v_texturePosition = g_texturePosition[index];
EmitVertex();
}
diff --git a/slideshow/opengl/vortexVertexShader.glsl b/slideshow/opengl/vortexVertexShader.glsl
index 603c62960f2a..9bab2d9e0397 100644
--- a/slideshow/opengl/vortexVertexShader.glsl
+++ b/slideshow/opengl/vortexVertexShader.glsl
@@ -16,6 +16,7 @@ in vec3 a_normal;
in vec2 a_texCoord;
in float tileInfo;
+uniform mat4 u_projectionMatrix;
uniform mat4 u_modelViewMatrix;
uniform mat4 u_sceneTransformMatrix;
uniform mat4 u_primitiveTransformMatrix;
@@ -25,10 +26,15 @@ uniform float time;
uniform ivec2 numTiles;
uniform sampler2D permTexture;
uniform float slide;
+uniform float shadow;
+uniform mat4 orthoProjectionMatrix;
+uniform mat4 orthoViewMatrix;
out vec2 g_texturePosition;
out vec3 g_normal;
+out mat4 projectionMatrix;
out mat4 modelViewMatrix;
+out mat4 shadowMatrix;
out mat4 transform;
out float nTime;
out float startTime;
@@ -134,13 +140,14 @@ void main( void )
* rotationMatrix(vec3(0.0, 1.0, 0.0), clamp(rotation, -1.0, 1.0) * M_PI)
* translationMatrix(-translationVector)
* transform;
+ }
- // Add a translation movement to the leaving slide so it doesn’t exactly mirror the entering one.
- if (isLeavingSlide && nTime > 0.3)
- {
- float movement = smoothstep(0.0, 1.0, (nTime - 0.3) * 2.0);
- transform = translationMatrix(vec3(-movement, 0.0, -0.5 * movement)) * transform;
- }
+ if (shadow < 0.5) {
+ projectionMatrix = u_projectionMatrix;
+ shadowMatrix = orthoProjectionMatrix * orthoViewMatrix;
+ } else {
+ projectionMatrix = orthoProjectionMatrix * orthoViewMatrix;
+ shadowMatrix = mat4(0.0);
}
modelViewMatrix = u_modelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;