summaryrefslogtreecommitdiff
path: root/slideshow/opengl
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <emmanuel.peyrot@collabora.com>2015-12-09 21:39:26 +0000
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2015-12-11 15:29:00 +0100
commit859e64aa730fa380ecaab92527e2cfe97c299a4f (patch)
tree6eaaaf61ac6b422e6d30f49c397f6204f87d6fff /slideshow/opengl
parenta74e8ab7841a67ae353c537d449d27a931ba67d8 (diff)
slideshow: Fix lighting in the Vortex transition
Change-Id: I870ef7885fe569c89bde63a70ef038c4133ffbfd
Diffstat (limited to 'slideshow/opengl')
-rwxr-xr-xslideshow/opengl/vortexFragmentShader.glsl12
-rwxr-xr-xslideshow/opengl/vortexVertexShader.glsl32
2 files changed, 36 insertions, 8 deletions
diff --git a/slideshow/opengl/vortexFragmentShader.glsl b/slideshow/opengl/vortexFragmentShader.glsl
index 9b7741acb100..3e104b2da545 100755
--- a/slideshow/opengl/vortexFragmentShader.glsl
+++ b/slideshow/opengl/vortexFragmentShader.glsl
@@ -14,19 +14,27 @@ uniform sampler2D enteringSlideTexture;
uniform float time;
varying vec2 v_texturePosition;
varying float v_textureSelect;
+varying vec3 v_normal;
void main()
{
+ vec3 lightVector = vec3(0.0, 0.0, 1.0);
+ float light = abs(dot(lightVector, v_normal));
+ vec4 fragment;
+
if (v_textureSelect == 0)
{
- gl_FragColor = texture2D(leavingSlideTexture, v_texturePosition);
+ fragment = texture2D(leavingSlideTexture, v_texturePosition);
}
else
{
vec2 pos = v_texturePosition;
pos.x = 1 - pos.x;
- gl_FragColor = texture2D(enteringSlideTexture, pos);
+ fragment = texture2D(enteringSlideTexture, pos);
}
+
+ vec4 black = vec4(0.0, 0.0, 0.0, fragment.a);
+ gl_FragColor = mix(black, fragment, light);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/slideshow/opengl/vortexVertexShader.glsl b/slideshow/opengl/vortexVertexShader.glsl
index ff86546d24c6..b2f94c58bc57 100755
--- a/slideshow/opengl/vortexVertexShader.glsl
+++ b/slideshow/opengl/vortexVertexShader.glsl
@@ -11,11 +11,23 @@
#define M_PI 3.1415926535897932384626433832795
+attribute vec3 a_position;
+attribute vec3 a_normal;
+attribute vec2 a_texCoord;
+
+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;
+
uniform float time;
uniform ivec2 numTiles;
uniform sampler2D permTexture;
attribute float tileInfo;
-varying vec2 v_texturePosition;
varying float v_textureSelect;
float snoise(vec2 p)
@@ -38,7 +50,8 @@ mat4 rotationMatrix(vec3 axis, float angle)
void main( void )
{
- vec4 v = gl_Vertex;
+ vec4 v = vec4(a_position, 1.0);
+ vec4 normal = vec4(a_normal, 1.0);
// Not sure it this is like what it should eventually be; just
// experimenting to get at least something.
@@ -82,7 +95,9 @@ void main( void )
float rotation = direction * (time - startTime) / (endTime - startTime);
// Avoid z fighting
- v = rotationMatrix(vec3(0, 1, 0), max(min(rotation, ALMOST_ONE), -ALMOST_ONE)*M_PI) * v;
+ mat4 matrix = rotationMatrix(vec3(0, 1, 0), max(min(rotation, ALMOST_ONE), -ALMOST_ONE)*M_PI);
+ v = matrix * v;
+ normal = matrix * normal;
v_textureSelect = float(rotation > 0.5 || rotation < -0.5);
}
@@ -91,14 +106,19 @@ void main( void )
// At end location. Tile is 180 degrees rotated
// Avoid z fighting
- v = rotationMatrix(vec3(0, 1, 0), direction*ALMOST_ONE*M_PI) * v;
+ mat4 matrix = rotationMatrix(vec3(0, 1, 0), direction*ALMOST_ONE*M_PI);
+ v = matrix * v;
+ normal = matrix * normal;
v_textureSelect = 1;
}
- gl_Position = gl_ModelViewProjectionMatrix * v;
+ mat4 modelViewMatrix = u_modelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
+ mat3 normalMatrix = mat3(transpose(inverse(modelViewMatrix)));
+ gl_Position = u_projectionMatrix * modelViewMatrix * v;
- v_texturePosition = gl_MultiTexCoord0.xy;
+ v_texturePosition = a_texCoord;
+ v_normal = normalize(normalMatrix * vec3(normal));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */