basicVertexShader.glsl 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /*************************************************************************
  3. *
  4. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5. *
  6. * Copyright 2008 by Sun Microsystems, Inc.
  7. *
  8. * OpenOffice.org - a multi-platform office productivity suite
  9. *
  10. * This file is part of OpenOffice.org.
  11. *
  12. * OpenOffice.org is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Lesser General Public License version 3
  14. * only, as published by the Free Software Foundation.
  15. *
  16. * OpenOffice.org is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Lesser General Public License version 3 for more details
  20. * (a copy is included in the LICENSE file that accompanied this code).
  21. *
  22. * You should have received a copy of the GNU Lesser General Public License
  23. * version 3 along with OpenOffice.org. If not, see
  24. * <http://www.openoffice.org/license.html>
  25. * for a copy of the LGPLv3 License.
  26. *
  27. ************************************************************************/
  28. #version 120
  29. attribute vec3 a_position;
  30. attribute vec3 a_normal;
  31. attribute vec2 a_texCoord;
  32. uniform mat4 u_projectionMatrix;
  33. uniform mat4 u_modelViewMatrix;
  34. uniform mat4 u_sceneTransformMatrix;
  35. uniform mat4 u_primitiveTransformMatrix;
  36. uniform mat4 u_operationsTransformMatrix;
  37. varying vec2 v_texturePosition;
  38. varying vec3 v_normal;
  39. #if __VERSION__ < 140
  40. mat4 inverse(mat4 m)
  41. {
  42. float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2], a03 = m[0][3];
  43. float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2], a13 = m[1][3];
  44. float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2], a23 = m[2][3];
  45. float a30 = m[3][0], a31 = m[3][1], a32 = m[3][2], a33 = m[3][3];
  46. float b00 = a00 * a11 - a01 * a10;
  47. float b01 = a00 * a12 - a02 * a10;
  48. float b02 = a00 * a13 - a03 * a10;
  49. float b03 = a01 * a12 - a02 * a11;
  50. float b04 = a01 * a13 - a03 * a11;
  51. float b05 = a02 * a13 - a03 * a12;
  52. float b06 = a20 * a31 - a21 * a30;
  53. float b07 = a20 * a32 - a22 * a30;
  54. float b08 = a20 * a33 - a23 * a30;
  55. float b09 = a21 * a32 - a22 * a31;
  56. float b10 = a21 * a33 - a23 * a31;
  57. float b11 = a22 * a33 - a23 * a32;
  58. float det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
  59. return mat4(
  60. a11 * b11 - a12 * b10 + a13 * b09,
  61. a02 * b10 - a01 * b11 - a03 * b09,
  62. a31 * b05 - a32 * b04 + a33 * b03,
  63. a22 * b04 - a21 * b05 - a23 * b03,
  64. a12 * b08 - a10 * b11 - a13 * b07,
  65. a00 * b11 - a02 * b08 + a03 * b07,
  66. a32 * b02 - a30 * b05 - a33 * b01,
  67. a20 * b05 - a22 * b02 + a23 * b01,
  68. a10 * b10 - a11 * b08 + a13 * b06,
  69. a01 * b08 - a00 * b10 - a03 * b06,
  70. a30 * b04 - a31 * b02 + a33 * b00,
  71. a21 * b02 - a20 * b04 - a23 * b00,
  72. a11 * b07 - a10 * b09 - a12 * b06,
  73. a00 * b09 - a01 * b07 + a02 * b06,
  74. a31 * b01 - a30 * b03 - a32 * b00,
  75. a20 * b03 - a21 * b01 + a22 * b00) / det;
  76. }
  77. #endif
  78. void main( void )
  79. {
  80. mat4 modelViewMatrix = u_modelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
  81. mat3 normalMatrix = mat3(transpose(inverse(modelViewMatrix)));
  82. gl_Position = u_projectionMatrix * modelViewMatrix * vec4(a_position, 1.0);
  83. v_texturePosition = a_texCoord;
  84. v_normal = normalize(normalMatrix * a_normal);
  85. }
  86. /* vim:set shiftwidth=4 softtabstop=4 expandtab: */