summaryrefslogtreecommitdiff
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
parentc5228bd0e430c3e45383939cdbd3e6dc7ee9dca6 (diff)
slideshow: Improve the performances of the Honeycomb transition
Change-Id: Iacddc7b84bf0be8bb112cba88cc7fd36f72e7ca0
-rw-r--r--slideshow/Package_opengl.mk3
-rw-r--r--slideshow/opengl/honeycombFragmentShader.glsl63
-rw-r--r--slideshow/opengl/honeycombGeometryShader.glsl64
-rw-r--r--slideshow/opengl/honeycombVertexShader.glsl83
-rw-r--r--slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx135
5 files changed, 297 insertions, 51 deletions
diff --git a/slideshow/Package_opengl.mk b/slideshow/Package_opengl.mk
index 1293c05f62c4..5e9c8d384ecb 100644
--- a/slideshow/Package_opengl.mk
+++ b/slideshow/Package_opengl.mk
@@ -15,6 +15,9 @@ $(eval $(call gb_Package_add_files,slideshow_opengl_shader,$(LIBO_ETC_FOLDER)/op
dissolveFragmentShader.glsl \
fadeBlackFragmentShader.glsl \
fadeFragmentShader.glsl \
+ honeycombVertexShader.glsl \
+ honeycombGeometryShader.glsl \
+ honeycombFragmentShader.glsl \
reflectionVertexShader.glsl \
reflectionFragmentShader.glsl \
staticFragmentShader.glsl \
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: */
diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
index d432e72dbbee..36ee0e767e97 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
@@ -1804,70 +1804,103 @@ std::shared_ptr<OGLTransitionImpl> makeGlitter()
return makeSimpleTransition(aLeavingSlide, aEnteringSlide);
}
-std::shared_ptr<OGLTransitionImpl> makeHoneycomb()
+namespace
{
- const int NX = 21;
- const int NY = 21;
- Primitives_t aLeavingSlide;
- Primitives_t aEnteringSlide;
+class HoneycombTransition : public PermTextureTransition
+{
+public:
+ HoneycombTransition(const TransitionScene& rScene, const TransitionSettings& rSettings)
+ : PermTextureTransition(rScene, rSettings)
+ {
+ }
- float fRandom = 0.0f;
+private:
+ virtual GLuint makeShader() const override;
+ virtual void prepareTransition( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex ) override;
+ virtual void displaySlides_( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale ) override;
- int centerX = NX / 2;
- int centerY = NY / 2;
+ GLint maHexagonSizeLocation = 0;
+ GLint maTimeLocation = 0;
+ GLint maSelectedTextureLocation = 0;
+};
- for (int y = 0; y < NY+2; y+=2)
- {
- for (int x = 0; x < NX+2; x+=2)
- {
- Primitive aHexagon;
- createHexagon(aHexagon, x, y, NX, NY);
+GLuint HoneycombTransition::makeShader() const
+{
+ return OpenGLHelper::LoadShaders( "honeycombVertexShader", "honeycombFragmentShader", "honeycombGeometryShader" );
+}
- fRandom = comphelper::rng::uniform_real_distribution(0.2, std::nextafter(0.7, DBL_MAX));
+void HoneycombTransition::prepareTransition( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex )
+{
+ CHECK_GL_ERROR();
+ PermTextureTransition::prepareTransition( glLeavingSlideTex, glEnteringSlideTex );
- aHexagon.Operations.push_back(makeSRotate(glm::vec3(0, 0, 1), glm::vec3(0, 0, 0), 0 , false, -1, 0.1));
- aHexagon.Operations.push_back(makeSRotate(glm::vec3(0, 0, 1), glm::vec3(0, 0, 0), 90 , true, 0.2, 1.0));
- if (x <= 0 || y <= 0 || x >= NX || y >= NY)
- {
- aHexagon.Operations.push_back(makeSTranslate(glm::vec3 (0, 0, 100), false, 0.1, 1.0));
- }
- else if ((centerX - 1 <= x && x <= centerX + 1 && centerY - 1 <= y && y <= centerY + 1 ))
- {
- aHexagon.Operations.push_back(makeSTranslate(glm::vec3 (0, 0, 7), true, 0.0, 1.0));
- aHexagon.Operations.push_back(makeSTranslate(glm::vec3 (0, 0, 100), false, 0.1, 1.0));
- }
- else
- {
- aHexagon.Operations.push_back(makeSTranslate(glm::vec3 (0, 0, 7), true, 0.0, 1.0));
- aHexagon.Operations.push_back(makeSTranslate(glm::vec3 (0, 0, 100), false, fRandom, 1.0));
- }
+ CHECK_GL_ERROR();
+ maHexagonSizeLocation = glGetUniformLocation(m_nProgramObject, "hexagonSize");
+ maTimeLocation = glGetUniformLocation( m_nProgramObject, "time" );
+ maSelectedTextureLocation = glGetUniformLocation( m_nProgramObject, "selectedTexture" );
+ CHECK_GL_ERROR();
- aLeavingSlide.push_back(aHexagon);
+ // We want to see the entering slide behind the leaving one.
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ CHECK_GL_ERROR();
+}
- aHexagon.Operations.clear();
+void HoneycombTransition::displaySlides_( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex,
+ double SlideWidthScale, double SlideHeightScale )
+{
+ CHECK_GL_ERROR();
+ applyOverallOperations( nTime, SlideWidthScale, SlideHeightScale );
+ glUniform1f( maTimeLocation, nTime );
- aHexagon.Operations.push_back(makeSRotate(glm::vec3(0, 0, 1), glm::vec3(0, 0, 0), -90 , false, -1, 0.0));
- aHexagon.Operations.push_back(makeSRotate(glm::vec3(0, 0, 1), glm::vec3(0, 0, 0), 90 , true, 0.0, 0.8));
+ // The back (entering) slide needs to be drawn before the front (leaving) one in order for blending to work.
- aHexagon.Operations.push_back(makeSTranslate(glm::vec3(-100, 0, -20), false, -1, 0));
+ const float borderSize = 0.15;
- if (x <= 0 || y <= 0 || x >= NX || y >= NY)
- {
- fRandom = comphelper::rng::uniform_real_distribution(0.85, std::nextafter(0.95, DBL_MAX));
- aHexagon.Operations.push_back(makeSTranslate(glm::vec3(100, 0, 0), false, fRandom, 0.95));
- }
- else
- {
- fRandom = comphelper::rng::uniform_real_distribution(0.3, std::nextafter(0.8, DBL_MAX));
- aHexagon.Operations.push_back(makeSTranslate(glm::vec3(100, 0, 0), false, fRandom, 0.9));
- }
- aHexagon.Operations.push_back(makeSTranslate(glm::vec3 (0, 0, 20), true, 0.1, 1.0));
- aEnteringSlide.push_back(aHexagon);
- }
- }
+ CHECK_GL_ERROR();
+ glUniform1f(maSelectedTextureLocation, 0.0);
+ glUniform1f(maHexagonSizeLocation, 1.0 - borderSize);
+ displaySlide( nTime, glEnteringSlideTex, getScene().getEnteringSlide(), SlideWidthScale, SlideHeightScale );
+ glUniform1f(maHexagonSizeLocation, 1.0 + borderSize);
+ displaySlide( nTime, glEnteringSlideTex, getScene().getEnteringSlide(), SlideWidthScale, SlideHeightScale );
+ CHECK_GL_ERROR();
- return makeSimpleTransition(aLeavingSlide, aEnteringSlide);
+ glUniform1f(maSelectedTextureLocation, 1.0);
+ glUniform1f(maHexagonSizeLocation, 1.0 - borderSize);
+ displaySlide( nTime, glLeavingSlideTex, getScene().getLeavingSlide(), SlideWidthScale, SlideHeightScale );
+ glUniform1f(maHexagonSizeLocation, 1.0 + borderSize);
+ displaySlide( nTime, glLeavingSlideTex, getScene().getLeavingSlide(), SlideWidthScale, SlideHeightScale );
+}
+
+std::shared_ptr<OGLTransitionImpl>
+makeHoneycombTransition(const Primitives_t& rLeavingSlidePrimitives,
+ const Primitives_t& rEnteringSlidePrimitives,
+ const TransitionSettings& rSettings = TransitionSettings())
+{
+ // The center point should be adjustable by the user, but we have no way to do that in the UI
+ return std::make_shared<HoneycombTransition>(TransitionScene(rLeavingSlidePrimitives, rEnteringSlidePrimitives),
+ rSettings);
+}
+
+}
+
+std::shared_ptr<OGLTransitionImpl> makeHoneycomb()
+{
+ const int NX = 21;
+ const int NY = 21;
+
+ TransitionSettings aSettings;
+ aSettings.mnRequiredGLVersion = 3.2;
+
+ Primitives_t aSlide;
+ Primitive aHexagon;
+ for (int y = 0; y < NY+2; y+=2)
+ for (int x = 0; x < NX+2; x+=2)
+ aHexagon.pushTriangle(glm::vec2(y % 4 ? fdiv(x, NX) : fdiv(x + 1, NX), fdiv(y, NY)), glm::vec2(1, 0), glm::vec2(0, 0));
+ aSlide.push_back(aHexagon);
+
+ return makeHoneycombTransition(aSlide, aSlide, aSettings);
}
std::shared_ptr<OGLTransitionImpl> makeNewsflash()