diff options
author | Emmanuel Gil Peyrot <emmanuel.peyrot@collabora.com> | 2016-02-24 20:21:13 +0000 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2016-02-25 11:16:45 +0000 |
commit | 3ed1e68a79e8dcc623eb9165577e0571cebf4709 (patch) | |
tree | 38b036104201c6888b3f6f49be4ac1fb3e256196 /slideshow/opengl | |
parent | 1a9b62dc661a26c02db34ab5075b4e209a70b196 (diff) |
slideshow: Blur the shadows the further they are from the object
Change-Id: I63f4fda670b86db2ee1ea66d8755d71697fac0c7
Reviewed-on: https://gerrit.libreoffice.org/22678
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'slideshow/opengl')
-rw-r--r-- | slideshow/opengl/honeycombFragmentShader.glsl | 30 | ||||
-rw-r--r-- | slideshow/opengl/honeycombGeometryShader.glsl | 15 | ||||
-rw-r--r-- | slideshow/opengl/vortexFragmentShader.glsl | 46 |
3 files changed, 74 insertions, 17 deletions
diff --git a/slideshow/opengl/honeycombFragmentShader.glsl b/slideshow/opengl/honeycombFragmentShader.glsl index c207203a1ce3..e4ce8e31f91e 100644 --- a/slideshow/opengl/honeycombFragmentShader.glsl +++ b/slideshow/opengl/honeycombFragmentShader.glsl @@ -29,6 +29,18 @@ bool isBorder(vec2 point) 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) + ); + vec4 fragment = vec4(texture(slideTexture, texturePosition).rgb, 1.0); vec3 lightVector = vec3(0.0, 0.0, 1.0); float light = max(dot(lightVector, normal), 0.0); @@ -73,13 +85,23 @@ void main() fragment.rgb *= actualTime; } } + + // Compute the shadow. float visibility = 1.0; const float epsilon = 0.0001; - if (texture(depthShadowTexture, shadowCoordinate.xy).r < shadowCoordinate.z - epsilon) - visibility *= 0.7 + 0.3 * (1.0 - texture(colorShadowTexture, shadowCoordinate.xy).a); + if (selectedTexture < 0.5) { + float depthShadow = texture(depthShadowTexture, shadowCoordinate.xy).z; + float shadowRadius = (1.0 / (shadowCoordinate.z - depthShadow)) * 1000.0; + // Only the entering slide. + for (int i = 0; i < 9; ++i) { + vec2 coordinate = shadowCoordinate.xy + samplingPoints[i] / shadowRadius; + if (depthShadow < shadowCoordinate.z - epsilon) { + visibility -= 0.05 * texture(colorShadowTexture, coordinate).a; + } + } + } + vec4 black = vec4(0.0, 0.0, 0.0, fragment.a); - if (fragment.a < 0.001) - discard; gl_FragColor = mix(black, fragment, visibility * light); } diff --git a/slideshow/opengl/honeycombGeometryShader.glsl b/slideshow/opengl/honeycombGeometryShader.glsl index 5afaa7b95aea..dedc0df97526 100644 --- a/slideshow/opengl/honeycombGeometryShader.glsl +++ b/slideshow/opengl/honeycombGeometryShader.glsl @@ -67,13 +67,14 @@ void emitHexagonVertex(vec3 center, vec2 translation) 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); + const vec2 translateVectors[6] = vec2[]( + vec2(-3, -2), + vec2(0, -4), + vec2(3, -2), + vec2(3, 2), + vec2(0, 4), + vec2(-3, 2) + ); vec3 center = gl_in[0].gl_Position.xyz; 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); } |