vortexFragmentShader.glsl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /*
  3. * This file is part of the LibreOffice project.
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. */
  9. #version 150
  10. uniform sampler2D slideTexture;
  11. uniform sampler2D leavingShadowTexture;
  12. uniform sampler2D enteringShadowTexture;
  13. in vec2 v_texturePosition;
  14. in vec3 v_normal;
  15. in vec4 shadowCoordinate;
  16. void main() {
  17. const vec2 samplingPoints[9] = vec2[](
  18. vec2(0, 0),
  19. vec2(-1, -1),
  20. vec2(-1, 0),
  21. vec2(-1, 1),
  22. vec2(0, 1),
  23. vec2(1, 1),
  24. vec2(1, 0),
  25. vec2(1, -1),
  26. vec2(0, -1)
  27. );
  28. // Compute the shadow...
  29. float visibility = 1.0;
  30. const float epsilon = 0.0001;
  31. // for the leaving slide,
  32. {
  33. float depthShadow = texture(leavingShadowTexture, shadowCoordinate.xy).r;
  34. float shadowRadius = (1.0 / (shadowCoordinate.z - depthShadow)) * 1000.0;
  35. for (int i = 0; i < 9; ++i) {
  36. vec2 coordinate = shadowCoordinate.xy + samplingPoints[i] / shadowRadius;
  37. if (texture(leavingShadowTexture, coordinate).r < shadowCoordinate.z - epsilon) {
  38. visibility -= 0.05;
  39. }
  40. }
  41. }
  42. // and for entering slide.
  43. {
  44. float depthShadow = texture(enteringShadowTexture, shadowCoordinate.xy).r;
  45. float shadowRadius = (1.0 / (shadowCoordinate.z - depthShadow)) * 1000.0;
  46. for (int i = 0; i < 9; ++i) {
  47. vec2 coordinate = shadowCoordinate.xy + samplingPoints[i] / shadowRadius;
  48. if (texture(enteringShadowTexture, coordinate).r < shadowCoordinate.z - epsilon) {
  49. visibility -= 0.05;
  50. }
  51. }
  52. }
  53. vec3 lightVector = vec3(0.0, 0.0, 1.0);
  54. float light = max(dot(lightVector, v_normal), 0.0);
  55. vec4 fragment = texture(slideTexture, v_texturePosition);
  56. vec4 black = vec4(0.0, 0.0, 0.0, fragment.a);
  57. gl_FragColor = mix(black, fragment, visibility * light);
  58. }
  59. /* vim:set shiftwidth=4 softtabstop=4 expandtab: */