From 3ed1e68a79e8dcc623eb9165577e0571cebf4709 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 24 Feb 2016 20:21:13 +0000 Subject: slideshow: Blur the shadows the further they are from the object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I63f4fda670b86db2ee1ea66d8755d71697fac0c7 Reviewed-on: https://gerrit.libreoffice.org/22678 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- slideshow/opengl/vortexFragmentShader.glsl | 46 ++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'slideshow/opengl/vortexFragmentShader.glsl') diff --git a/slideshow/opengl/vortexFragmentShader.glsl b/slideshow/opengl/vortexFragmentShader.glsl index a3f8191eeb78..6bcdfc5dab22 100644 --- a/slideshow/opengl/vortexFragmentShader.glsl +++ b/slideshow/opengl/vortexFragmentShader.glsl @@ -18,15 +18,49 @@ in vec3 v_normal; in vec4 shadowCoordinate; void main() { + const vec2 samplingPoints[9] = vec2[]( + vec2(0, 0), + vec2(-1, -1), + vec2(-1, 0), + vec2(-1, 1), + vec2(0, 1), + vec2(1, 1), + vec2(1, 0), + vec2(1, -1), + vec2(0, -1) + ); + + // Compute the shadow... + float visibility = 1.0; + const float epsilon = 0.0001; + + // for the leaving slide, + { + float depthShadow = texture(leavingShadowTexture, shadowCoordinate.xy).r; + float shadowRadius = (1.0 / (shadowCoordinate.z - depthShadow)) * 1000.0; + for (int i = 0; i < 9; ++i) { + vec2 coordinate = shadowCoordinate.xy + samplingPoints[i] / shadowRadius; + if (texture(leavingShadowTexture, coordinate).r < shadowCoordinate.z - epsilon) { + visibility -= 0.05; + } + } + } + + // and for entering slide. + { + float depthShadow = texture(enteringShadowTexture, shadowCoordinate.xy).r; + float shadowRadius = (1.0 / (shadowCoordinate.z - depthShadow)) * 1000.0; + for (int i = 0; i < 9; ++i) { + vec2 coordinate = shadowCoordinate.xy + samplingPoints[i] / shadowRadius; + if (texture(enteringShadowTexture, coordinate).r < shadowCoordinate.z - epsilon) { + visibility -= 0.05; + } + } + } + vec3 lightVector = vec3(0.0, 0.0, 1.0); float light = max(dot(lightVector, v_normal), 0.0); vec4 fragment = texture(slideTexture, v_texturePosition); - float visibility = 1.0; - const float epsilon = 0.0001; - if (texture(leavingShadowTexture, shadowCoordinate.xy).r < shadowCoordinate.z - epsilon) - visibility *= 0.7; - if (texture(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); } -- cgit