From d323f2487d84fbd3909cd2166b98a2a875b71bf8 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 9 Feb 2016 23:59:16 +0000 Subject: slideshow: Add shadows to Honeycomb, using the same way as Vortex Change-Id: I1f8f11f900f281792b417c1efead272fe3e8432e --- slideshow/opengl/honeycombFragmentShader.glsl | 11 ++++++++- slideshow/opengl/honeycombGeometryShader.glsl | 32 +++++++++++++++++++++++++-- slideshow/opengl/honeycombVertexShader.glsl | 20 ++++++++++++++--- 3 files changed, 57 insertions(+), 6 deletions(-) (limited to 'slideshow/opengl') diff --git a/slideshow/opengl/honeycombFragmentShader.glsl b/slideshow/opengl/honeycombFragmentShader.glsl index 7e529517915f..41b6738a804f 100644 --- a/slideshow/opengl/honeycombFragmentShader.glsl +++ b/slideshow/opengl/honeycombFragmentShader.glsl @@ -13,8 +13,11 @@ in vec2 texturePosition; in float fuzz; in vec2 v_center; in vec3 normal; +in vec4 shadowCoordinate; uniform sampler2D slideTexture; +uniform sampler2D colorShadowTexture; +uniform sampler2D depthShadowTexture; uniform float selectedTexture; uniform float time; uniform float hexagonSize; @@ -70,8 +73,14 @@ void main() fragment.rgb *= actualTime; } } + float visibility = 1.0; + const float epsilon = 0.0001; + if (texture2D(depthShadowTexture, shadowCoordinate.xy).r < shadowCoordinate.z - epsilon) + visibility *= 0.7 + 0.3 * (1.0 - texture2D(colorShadowTexture, shadowCoordinate.xy).a); vec4 black = vec4(0.0, 0.0, 0.0, fragment.a); - gl_FragColor = mix(black, fragment, light); + if (fragment.a < 0.001) + discard; + gl_FragColor = mix(black, fragment, visibility * light); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/slideshow/opengl/honeycombGeometryShader.glsl b/slideshow/opengl/honeycombGeometryShader.glsl index f1c0c7058162..5269fad45e1c 100644 --- a/slideshow/opengl/honeycombGeometryShader.glsl +++ b/slideshow/opengl/honeycombGeometryShader.glsl @@ -12,7 +12,9 @@ layout(triangles) in; layout(triangle_strip, max_vertices=27) out; -in mat4 modelViewProjectionMatrix[]; +in mat4 projectionMatrix[]; +in mat4 modelViewMatrix[]; +in mat4 shadowMatrix[]; uniform float hexagonSize; uniform sampler2D permTexture; @@ -21,6 +23,7 @@ out vec2 texturePosition; out float fuzz; out vec2 v_center; out vec3 normal; +out vec4 shadowCoordinate; const float expandFactor = 0.0318; @@ -29,10 +32,35 @@ float snoise(vec2 p) return texture2D(permTexture, p).r; } +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(vec3 center, vec2 translation) { vec4 pos = vec4(center + hexagonSize * expandFactor * vec3(translation, 0.0), 1.0); - gl_Position = modelViewProjectionMatrix[0] * pos; + gl_Position = projectionMatrix[0] * modelViewMatrix[0] * pos; + shadowCoordinate = translationMatrix(vec3(0.5, 0.5, 0.5)) * scaleMatrix(vec3(0.5, 0.5, 0.5)) * shadowMatrix[0] * modelViewMatrix[0] * pos; texturePosition = vec2((pos.x + 1), (1 - pos.y)) / 2; EmitVertex(); } diff --git a/slideshow/opengl/honeycombVertexShader.glsl b/slideshow/opengl/honeycombVertexShader.glsl index d54783b82b7b..32fdecef01f9 100644 --- a/slideshow/opengl/honeycombVertexShader.glsl +++ b/slideshow/opengl/honeycombVertexShader.glsl @@ -21,8 +21,13 @@ uniform mat4 u_operationsTransformMatrix; uniform float time; uniform float selectedTexture; +uniform float shadow; +uniform mat4 orthoProjectionMatrix; +uniform mat4 orthoViewMatrix; -out mat4 modelViewProjectionMatrix; +out mat4 projectionMatrix; +out mat4 modelViewMatrix; +out mat4 shadowMatrix; mat4 translationMatrix(vec3 axis) { @@ -55,7 +60,7 @@ mat4 rotationMatrix(vec3 axis, float angle) void main( void ) { - mat4 modelViewMatrix = u_modelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix; + mat4 nmodelViewMatrix = u_modelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix; mat4 transformMatrix; // TODO: use the aspect ratio of the slide instead. @@ -76,7 +81,16 @@ void main( void ) * rotationMatrix(vec3(0.0, 0.0, 1.0), pow(0.8 * (time - 1.0), 2.0) * M_PI) * invertSlideScaleMatrix; } - modelViewProjectionMatrix = u_projectionMatrix * modelViewMatrix * transformMatrix; + + if (shadow < 0.5) { + projectionMatrix = u_projectionMatrix; + shadowMatrix = orthoProjectionMatrix * orthoViewMatrix; + } else { + projectionMatrix = orthoProjectionMatrix * orthoViewMatrix; + shadowMatrix = mat4(0.0); + } + + modelViewMatrix = nmodelViewMatrix * transformMatrix; gl_Position = vec4(a_position, 1.0); } -- cgit