vortexGeometryShader.glsl 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. layout(triangles) in;
  11. layout(triangle_strip, max_vertices=11) out;
  12. uniform float shadow;
  13. uniform mat4 u_projectionMatrix;
  14. uniform mat4 orthoProjectionMatrix;
  15. uniform mat4 orthoViewMatrix;
  16. in vec2 g_texturePosition[];
  17. in vec3 g_normal[];
  18. in mat4 modelViewMatrix[];
  19. in mat4 transform[];
  20. in float nTime[];
  21. in float startTime[];
  22. in float endTime[];
  23. out vec2 v_texturePosition;
  24. out vec3 v_normal;
  25. out vec4 shadowCoordinate;
  26. mat4 identityMatrix(void)
  27. {
  28. return mat4(1.0, 0.0, 0.0, 0.0,
  29. 0.0, 1.0, 0.0, 0.0,
  30. 0.0, 0.0, 1.0, 0.0,
  31. 0.0, 0.0, 0.0, 1.0);
  32. }
  33. mat4 scaleMatrix(vec3 axis)
  34. {
  35. mat4 matrix = identityMatrix();
  36. matrix[0][0] = axis.x;
  37. matrix[1][1] = axis.y;
  38. matrix[2][2] = axis.z;
  39. return matrix;
  40. }
  41. mat4 translationMatrix(vec3 axis)
  42. {
  43. mat4 matrix = identityMatrix();
  44. matrix[3] = vec4(axis, 1.0);
  45. return matrix;
  46. }
  47. void emitHexagonVertex(int index, vec3 translation, float fdsq)
  48. {
  49. mat4 projectionMatrix;
  50. mat4 shadowMatrix;
  51. if (shadow < 0.5) {
  52. projectionMatrix = u_projectionMatrix;
  53. shadowMatrix = orthoProjectionMatrix * orthoViewMatrix;
  54. } else {
  55. projectionMatrix = orthoProjectionMatrix * orthoViewMatrix;
  56. shadowMatrix = mat4(0.0);
  57. }
  58. mat4 normalMatrix = transpose(inverse(modelViewMatrix[index]));
  59. vec4 pos = gl_in[index].gl_Position + vec4(translation, 0.0);
  60. // Apply our transform operations.
  61. pos = transform[index] * pos;
  62. v_normal = normalize(vec3(normalMatrix * transform[index] * vec4(g_normal[index], 0.0)));
  63. v_normal.z *= fdsq;
  64. gl_Position = projectionMatrix * modelViewMatrix[index] * pos;
  65. shadowCoordinate = translationMatrix(vec3(0.5, 0.5, 0.5)) * scaleMatrix(vec3(0.5, 0.5, 0.5)) * shadowMatrix * modelViewMatrix[index] * pos;
  66. v_texturePosition = g_texturePosition[index];
  67. EmitVertex();
  68. }
  69. void main()
  70. {
  71. const vec4 invalidPosition = vec4(-256.0, -256.0, -256.0, -256.0);
  72. const vec3 noTranslation = vec3(0.0, 0.0, 0.0);
  73. if (gl_in[0].gl_Position == invalidPosition)
  74. return;
  75. // Draw “walls” to the hexagons.
  76. if (nTime[0] > startTime[0] && nTime[0] <= endTime[0]) {
  77. const vec3 translation = vec3(0.0, 0.0, -0.02);
  78. emitHexagonVertex(2, noTranslation, 0.3);
  79. emitHexagonVertex(2, translation, 0.3);
  80. for (int i = 0; i < 3; ++i) {
  81. emitHexagonVertex(i, noTranslation, 0.3);
  82. emitHexagonVertex(i, translation, 0.3);
  83. }
  84. EndPrimitive();
  85. }
  86. // Draw the main quad part.
  87. for (int i = 0; i < 3; ++i) {
  88. emitHexagonVertex(i, noTranslation, 1.0);
  89. }
  90. EndPrimitive();
  91. }
  92. /* vim:set shiftwidth=4 softtabstop=4 expandtab: */