depth_cube.vert 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2025 Le Juez Victor
  3. *
  4. * This software is provided "as-is", without any express or implied warranty. In no event
  5. * will the authors be held liable for any damages arising from the use of this software.
  6. *
  7. * Permission is granted to anyone to use this software for any purpose, including commercial
  8. * applications, and to alter it and redistribute it freely, subject to the following restrictions:
  9. *
  10. * 1. The origin of this software must not be misrepresented; you must not claim that you
  11. * wrote the original software. If you use this software in a product, an acknowledgment
  12. * in the product documentation would be appreciated but is not required.
  13. *
  14. * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
  15. * as being the original software.
  16. *
  17. * 3. This notice may not be removed or altered from any source distribution.
  18. */
  19. #version 330 core
  20. /* === Constants === */
  21. const int MAX_BONES = 128;
  22. /* === Attributes === */
  23. layout(location = 0) in vec3 aPosition;
  24. layout(location = 1) in vec2 aTexCoord;
  25. layout(location = 3) in vec4 aColor;
  26. layout(location = 5) in ivec4 aBoneIDs;
  27. layout(location = 6) in vec4 aWeights;
  28. /* === Uniforms === */
  29. uniform mat4 uMatModel;
  30. uniform mat4 uMatMVP;
  31. uniform vec2 uTexCoordOffset;
  32. uniform vec2 uTexCoordScale;
  33. uniform float uAlpha;
  34. uniform mat4 uBoneMatrices[MAX_BONES];
  35. uniform bool uUseSkinning;
  36. /* === Varyings === */
  37. out vec3 vPosition;
  38. out vec2 vTexCoord;
  39. out float vAlpha;
  40. /* === Main function === */
  41. void main()
  42. {
  43. vec3 skinnedPosition = aPosition;
  44. if (uUseSkinning)
  45. {
  46. mat4 skinMatrix =
  47. aWeights.x * uBoneMatrices[aBoneIDs.x] +
  48. aWeights.y * uBoneMatrices[aBoneIDs.y] +
  49. aWeights.z * uBoneMatrices[aBoneIDs.z] +
  50. aWeights.w * uBoneMatrices[aBoneIDs.w];
  51. skinnedPosition = vec3(skinMatrix * vec4(aPosition, 1.0));
  52. }
  53. vec4 worldPosition = uMatModel * vec4(skinnedPosition, 1.0);
  54. vPosition = worldPosition.xyz;
  55. vTexCoord = uTexCoordOffset + aTexCoord * uTexCoordScale;
  56. vAlpha = uAlpha * aColor.a;
  57. gl_Position = uMatMVP * vec4(skinnedPosition, 1.0);
  58. }