[Libreoffice-commits] core.git: slideshow/opengl slideshow/source

Tor Lillqvist tml at collabora.com
Fri Nov 6 10:51:16 PST 2015


 slideshow/opengl/vortexFragmentShader.glsl                           |   17 +-
 slideshow/opengl/vortexVertexShader.glsl                             |   72 +++++++--
 slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx |   77 ++++++----
 3 files changed, 113 insertions(+), 53 deletions(-)

New commits:
commit 24db02dc8d771b8aa722d0fa2a410635b5179e35
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri Nov 6 17:44:52 2015 +0200

    Make the Vortex transition a bit more interesting
    
    Also some minor cleanups in the C++ code.
    
    Change-Id: I106657130dd6e32b458cb416717806caac5031ce

diff --git a/slideshow/opengl/vortexFragmentShader.glsl b/slideshow/opengl/vortexFragmentShader.glsl
index d4ff8fb..a8a9767 100755
--- a/slideshow/opengl/vortexFragmentShader.glsl
+++ b/slideshow/opengl/vortexFragmentShader.glsl
@@ -9,21 +9,22 @@
 
 uniform sampler2D leavingSlideTexture;
 uniform sampler2D enteringSlideTexture;
-uniform sampler2D permTexture;
 uniform float time;
 varying vec2 v_texturePosition;
-
-float snoise(vec2 p)
-{
-    return texture2D(permTexture, p).r;
-}
+varying float v_textureSelect;
 
 void main()
 {
-    if (time <= 0.5)
+    if (v_textureSelect == 0)
+    {
         gl_FragColor = texture2D(leavingSlideTexture, v_texturePosition);
+    }
     else
-        gl_FragColor = texture2D(enteringSlideTexture, v_texturePosition);
+    {
+        vec2 pos = v_texturePosition;
+        pos.x = 1 - pos.x;
+        gl_FragColor = texture2D(enteringSlideTexture, pos);
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/slideshow/opengl/vortexVertexShader.glsl b/slideshow/opengl/vortexVertexShader.glsl
index 588eda5..532260d 100755
--- a/slideshow/opengl/vortexVertexShader.glsl
+++ b/slideshow/opengl/vortexVertexShader.glsl
@@ -10,12 +10,14 @@
 #define M_PI 3.1415926535897932384626433832795
 
 uniform float time;
+uniform ivec2 numTiles;
 uniform sampler2D permTexture;
-attribute vec2 center;
+attribute vec2 tileCenter;
 attribute int tileXIndex;
 attribute int tileYIndex;
 attribute int vertexIndexInTile;
 varying vec2 v_texturePosition;
+varying float v_textureSelect;
 
 float snoise(vec2 p)
 {
@@ -35,14 +37,6 @@ mat4 rotationMatrix(vec3 axis, float angle)
                 0.0,                                0.0,                                0.0,                                1.0);
 }
 
-mat4 translateMatrix(vec2 whereTo)
-{
-    return mat4(1, 0, 0, whereTo.x,
-                0, 1, 0, whereTo.y,
-                0, 0, 1,         0,
-                0, 0, 0,         1);
-}
-
 void main( void )
 {
     vec4 v = gl_Vertex;
@@ -50,16 +44,62 @@ void main( void )
     // Of course this is nothing like what it will eventually be; just
     // experimenting to get at least something.
 
-    v -= vec4(center, 0, 0);
-    if (time <= 0.5)
-        v = rotationMatrix(vec3(0, 1, 0), time*M_PI) * v;
+    // Move the tile on a semicircular path so that it will end up at the correct place
+    // Move half the tiles one way, half the other.
+
+    // Each tile moves during only half of the transition. The letmost
+    // tiles start moving immediately and arrive at their end position
+    // at time=0.5, when the tiles there (the rightmost ones) start
+    // moving.
+
+    float startTime = float(tileXIndex)/(numTiles.x-1) * 0.5;
+    float endTime = startTime + 0.5;
+
+    if (time <= startTime)
+    {
+        // Still at start location, nothing needed
+        v_textureSelect = 0;
+    }
+    else if (time > startTime && time <= endTime)
+    {
+        // Moving
+        float moveTime = (time - startTime) * 2;
+
+        // First: Rotate the tile around its Y axis,
+        // It rotates 180 degrees during the transition.
+        // Translate to origin, rotate.
+
+        v -= vec4(tileCenter, 0, 0);
+
+        // A semi-random number 0..1, different for neighbouring tiles
+        float fuzz = snoise(256*vec2(float(tileXIndex)/(numTiles.x-1), float(tileYIndex)/(numTiles.y-1)));
+
+        float rotation = moveTime;
+
+        // experiment: perturb rotation a bit randomly
+        // rotation = moveTime - fuzz*(0.5-abs(time - 0.5));
+
+        v = rotationMatrix(vec3(0, 1, 0), rotation*M_PI) * v;
+
+        v.x += tileCenter.x * cos(moveTime*M_PI);
+        v.y += tileCenter.y;
+        v.z += (fuzz < 0.5 ? -1 : 1) * tileCenter.x * sin(moveTime*M_PI);
+
+        // Perturb z a bit randomly
+        v.z += ((((tileXIndex << 3) ^ tileYIndex) % 10) - 5) * (1 - abs(time-0.5)*2);
+
+        v_textureSelect = float(rotation > 0.5);
+    }
     else
-        v = rotationMatrix(vec3(0, 1, 0), -(1-time)*M_PI) * v;
-    v += vec4(center, 0, 0);
+    {
+        // At end location. Tile is 180 degrees rotated
 
-    // v.z += 10 * (snoise(vec2(tileXIndex, tileYIndex))-0.5) * (1 - abs(time-0.5)*2);
+        v -= vec4(tileCenter, 0, 0);
+        v = rotationMatrix(vec3(0, 1, 0), M_PI) * v;
+        v += vec4(-tileCenter.x, tileCenter.y, 0, 0);
 
-    v.z += ((((tileXIndex << 3) ^ tileYIndex) % 10) - 5) * (1 - abs(time-0.5)*2) + 0*vertexIndexInTile;
+        v_textureSelect = 1;
+    }
 
     gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * v;
 
diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
index a3183c6..fd3e73f 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
@@ -1511,25 +1511,32 @@ void ShaderTransition::impl_preparePermShader()
     CHECK_GL_ERROR();
     if( m_nProgramObject ) {
         glUseProgram( m_nProgramObject );
+        CHECK_GL_ERROR();
 
         GLint location = glGetUniformLocation( m_nProgramObject, "leavingSlideTexture" );
         if( location != -1 ) {
             glUniform1i( location, 0 );  // texture unit 0
+            CHECK_GL_ERROR();
         }
 
         glActiveTexture(GL_TEXTURE1);
+        CHECK_GL_ERROR();
         if( !m_nHelperTexture )
             initPermTexture( &m_nHelperTexture );
+
         glActiveTexture(GL_TEXTURE0);
+        CHECK_GL_ERROR();
 
         location = glGetUniformLocation( m_nProgramObject, "permTexture" );
         if( location != -1 ) {
             glUniform1i( location, 1 );  // texture unit 1
+            CHECK_GL_ERROR();
         }
 
         location = glGetUniformLocation( m_nProgramObject, "enteringSlideTexture" );
         if( location != -1 ) {
             glUniform1i( location, 2 );  // texture unit 2
+            CHECK_GL_ERROR();
         }
     }
     CHECK_GL_ERROR();
@@ -1652,21 +1659,20 @@ class VortexTransition : public ShaderTransition
 public:
     VortexTransition(const TransitionScene& rScene, const TransitionSettings& rSettings, int nNX, int nNY)
         : ShaderTransition(rScene, rSettings)
-        , mnCenterLocation(0)
+        , mnTileCenterLocation(0)
         , mnTileXIndexLocation(0)
         , mnTileYIndexLocation(0)
         , mnVertexIndexInTileLocation(0)
-        , mnCenterBuffer(0)
+        , mnTileCenterBuffer(0)
         , mnTileXIndexBuffer(0)
         , mnTileYIndexBuffer(0)
         , mnVertexIndexInTileBuffer(0)
-        , mnNX(nNX)
-        , mnNY(nNY)
+        , maNumTiles(nNX,nNY)
     {
-        mvCenters.resize(6*mnNX*mnNY);
-        mvTileXIndexes.resize(6*mnNX*mnNY);
-        mvTileYIndexes.resize(6*mnNX*mnNY);
-        mvVertexIndexesInTiles.resize(6*mnNX*mnNY);
+        mvTileCenters.resize(6*maNumTiles.x*maNumTiles.y);
+        mvTileXIndexes.resize(6*maNumTiles.x*maNumTiles.y);
+        mvTileYIndexes.resize(6*maNumTiles.x*maNumTiles.y);
+        mvVertexIndexesInTiles.resize(6*maNumTiles.x*maNumTiles.y);
     }
 
 private:
@@ -1676,18 +1682,18 @@ private:
 
     virtual GLuint makeShader() override;
 
-    GLint mnCenterLocation;
+    GLint mnTileCenterLocation;
     GLint mnTileXIndexLocation;
     GLint mnTileYIndexLocation;
     GLint mnVertexIndexInTileLocation;
-    GLuint mnCenterBuffer;
+    GLuint mnTileCenterBuffer;
     GLuint mnTileXIndexBuffer;
     GLuint mnTileYIndexBuffer;
     GLuint mnVertexIndexInTileBuffer;
 
-    int mnNX, mnNY;
+    glm::ivec2 maNumTiles;
 
-    std::vector<glm::vec2> mvCenters;
+    std::vector<glm::vec2> mvTileCenters;
     std::vector<GLint> mvTileXIndexes;
     std::vector<GLint> mvTileYIndexes;
     std::vector<GLint> mvVertexIndexesInTiles;
@@ -1697,11 +1703,11 @@ void VortexTransition::prepare( double, double, double, double, double )
 {
     glDisable(GL_CULL_FACE);
 
-    glBindBuffer(GL_ARRAY_BUFFER, mnCenterBuffer);
+    glBindBuffer(GL_ARRAY_BUFFER, mnTileCenterBuffer);
     CHECK_GL_ERROR();
-    glEnableVertexAttribArray(mnCenterLocation);
+    glEnableVertexAttribArray(mnTileCenterLocation);
     CHECK_GL_ERROR();
-    glVertexAttribPointer(mnCenterLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
+    glVertexAttribPointer(mnTileCenterLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
     CHECK_GL_ERROR();
 
     glBindBuffer(GL_ARRAY_BUFFER, mnTileXIndexBuffer);
@@ -1738,16 +1744,28 @@ GLuint VortexTransition::makeShader()
 {
     GLuint nProgram = OpenGLHelper::LoadShaders( "vortexVertexShader", "vortexFragmentShader" );
 
-    mnCenterLocation = glGetAttribLocation(nProgram, "center");
-    CHECK_GL_ERROR();
-    mnTileXIndexLocation = glGetAttribLocation(nProgram, "tileXIndex");
-    CHECK_GL_ERROR();
-    mnTileYIndexLocation = glGetAttribLocation(nProgram, "tileYIndex");
-    CHECK_GL_ERROR();
-    mnVertexIndexInTileLocation = glGetAttribLocation(nProgram, "vertexIndexInTile");
-    CHECK_GL_ERROR();
+    if (nProgram)
+    {
+        mnTileCenterLocation = glGetAttribLocation(nProgram, "tileCenter");
+        CHECK_GL_ERROR();
+        mnTileXIndexLocation = glGetAttribLocation(nProgram, "tileXIndex");
+        CHECK_GL_ERROR();
+        mnTileYIndexLocation = glGetAttribLocation(nProgram, "tileYIndex");
+        CHECK_GL_ERROR();
+        mnVertexIndexInTileLocation = glGetAttribLocation(nProgram, "vertexIndexInTile");
+        CHECK_GL_ERROR();
+
+        glUseProgram(nProgram);
+        CHECK_GL_ERROR();
 
-    glGenBuffers(1, &mnCenterBuffer);
+        GLint nNumTilesLocation = glGetUniformLocation(nProgram, "numTiles");
+        CHECK_GL_ERROR();
+
+        glUniform2iv(nNumTilesLocation, 1, glm::value_ptr(maNumTiles));
+        CHECK_GL_ERROR();
+    }
+
+    glGenBuffers(1, &mnTileCenterBuffer);
     CHECK_GL_ERROR();
     glGenBuffers(1, &mnTileXIndexBuffer);
     CHECK_GL_ERROR();
@@ -1759,9 +1777,9 @@ GLuint VortexTransition::makeShader()
     // Two triangles, i.e. six vertices, per tile
     {
         int n = 0;
-        for (int x = 0; x < mnNX; x++)
+        for (int x = 0; x < maNumTiles.x; x++)
         {
-            for (int y = 0; y < mnNY; y++)
+            for (int y = 0; y < maNumTiles.y; y++)
             {
                 for (int v = 0; v < 6; v++)
                 {
@@ -1770,7 +1788,7 @@ GLuint VortexTransition::makeShader()
                     // coordinates. Why the code can't use those from the start I don't
                     // know... Confusing. Anyway, so here when we store the center of each rectangle
                     // that the vertices belong to, we need to use the actual coordinates.
-                    mvCenters[n] = glm::vec2(2*((x+0.5)/mnNX) - 1, -2*((y+0.5)/mnNY) + 1);
+                    mvTileCenters[n] = glm::vec2(2*((x+0.5)/maNumTiles.x) - 1, -2*((y+0.5)/maNumTiles.y) + 1);
 
                     mvTileXIndexes[n] = x;
                     mvTileYIndexes[n] = y;
@@ -1781,9 +1799,9 @@ GLuint VortexTransition::makeShader()
         }
     }
 
-    glBindBuffer(GL_ARRAY_BUFFER, mnCenterBuffer);
+    glBindBuffer(GL_ARRAY_BUFFER, mnTileCenterBuffer);
     CHECK_GL_ERROR();
-    glBufferData(GL_ARRAY_BUFFER, mvCenters.size()*sizeof(glm::vec2), mvCenters.data(), GL_STATIC_DRAW);
+    glBufferData(GL_ARRAY_BUFFER, mvTileCenters.size()*sizeof(glm::vec2), mvTileCenters.data(), GL_STATIC_DRAW);
     CHECK_GL_ERROR();
 
     glBindBuffer(GL_ARRAY_BUFFER, mnTileXIndexBuffer);
@@ -1871,6 +1889,7 @@ GLuint RippleTransition::makeShader()
     if (nProgram)
     {
         glUseProgram(nProgram);
+        CHECK_GL_ERROR();
 
         GLint nCenterLocation = glGetUniformLocation(nProgram, "center");
         CHECK_GL_ERROR();


More information about the Libreoffice-commits mailing list