honeycombVertexShader.glsl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #define M_PI 3.1415926535897932384626433832795
  11. in vec3 a_position;
  12. uniform mat4 u_projectionMatrix;
  13. uniform mat4 u_modelViewMatrix;
  14. uniform mat4 u_sceneTransformMatrix;
  15. uniform mat4 u_primitiveTransformMatrix;
  16. uniform mat4 u_operationsTransformMatrix;
  17. uniform float time;
  18. uniform float selectedTexture;
  19. uniform float shadow;
  20. uniform mat4 orthoProjectionMatrix;
  21. uniform mat4 orthoViewMatrix;
  22. // Workaround for Intel's Windows driver, to prevent optimisation breakage.
  23. uniform float zero;
  24. out mat4 projectionMatrix;
  25. out mat4 modelViewMatrix;
  26. out mat4 shadowMatrix;
  27. mat4 identityMatrix(void)
  28. {
  29. return mat4(1.0, 0.0, 0.0, 0.0,
  30. 0.0, 1.0, 0.0, 0.0,
  31. 0.0, 0.0, 1.0, 0.0,
  32. 0.0, 0.0, 0.0, 1.0);
  33. }
  34. mat4 translationMatrix(vec3 axis)
  35. {
  36. return mat4(1.0, 0.0, 0.0, 0.0,
  37. 0.0, 1.0, 0.0, 0.0,
  38. 0.0, 0.0, 1.0, 0.0,
  39. axis.x, axis.y, axis.z, 1.0);
  40. }
  41. mat4 scaleMatrix(vec3 axis)
  42. {
  43. return mat4(axis.x, 0.0, 0.0, 0.0,
  44. 0.0, axis.y, 0.0, 0.0,
  45. 0.0, 0.0, axis.z, 0.0,
  46. 0.0, 0.0, 0.0, 1.0);
  47. }
  48. mat4 rotationMatrix(vec3 axis, float angle)
  49. {
  50. axis = normalize(axis);
  51. float s = sin(angle);
  52. float c = cos(angle);
  53. float oc = 1.0 - c;
  54. return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
  55. oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
  56. oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
  57. 0.0, 0.0, 0.0, 1.0);
  58. }
  59. void main( void )
  60. {
  61. mat4 nmodelViewMatrix = u_modelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
  62. mat4 transformMatrix = identityMatrix();
  63. // TODO: use the aspect ratio of the slide instead.
  64. mat4 slideScaleMatrix = scaleMatrix(vec3(0.75, 1, 1));
  65. mat4 invertSlideScaleMatrix = scaleMatrix(1.0 / vec3(0.75, 1, 1));
  66. // These ugly zero comparisons are a workaround for Intel's Windows driver optimisation bug.
  67. if (selectedTexture > 0.5) {
  68. // Leaving texture
  69. if (zero < 1.0)
  70. transformMatrix = invertSlideScaleMatrix * transformMatrix;
  71. if (zero < 2.0)
  72. transformMatrix = rotationMatrix(vec3(0.0, 0.0, 1.0), -pow(time, 3) * M_PI) * transformMatrix;
  73. if (zero < 3.0)
  74. transformMatrix = slideScaleMatrix * transformMatrix;
  75. if (zero < 4.0)
  76. transformMatrix = scaleMatrix(vec3(1 + pow(2 * time, 2.1), 1 + pow(2 * time, 2.1), 0)) * transformMatrix;
  77. if (zero < 5.0)
  78. transformMatrix = translationMatrix(vec3(0, 0, 6 * time)) * transformMatrix;
  79. } else {
  80. // Entering texture
  81. if (zero < 1.0)
  82. transformMatrix = invertSlideScaleMatrix * transformMatrix;
  83. if (zero < 2.0)
  84. transformMatrix = rotationMatrix(vec3(0.0, 0.0, 1.0), pow(0.8 * (time - 1.0), 2.0) * M_PI) * transformMatrix;
  85. if (zero < 3.0)
  86. transformMatrix = slideScaleMatrix * transformMatrix;
  87. if (zero < 4.0)
  88. transformMatrix = translationMatrix(vec3(0, 0, 28 * (sqrt(time) - 1))) * transformMatrix;
  89. }
  90. if (shadow < 0.5) {
  91. projectionMatrix = u_projectionMatrix;
  92. shadowMatrix = orthoProjectionMatrix * orthoViewMatrix;
  93. } else {
  94. projectionMatrix = orthoProjectionMatrix * orthoViewMatrix;
  95. shadowMatrix = mat4(0.0);
  96. }
  97. modelViewMatrix = nmodelViewMatrix * transformMatrix;
  98. gl_Position = vec4(a_position, 1.0);
  99. }
  100. /* vim:set shiftwidth=4 softtabstop=4 expandtab: */