shadowMap.vertex.fx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. precision highp float;
  2. // Attribute
  3. attribute vec3 position;
  4. #if NUM_BONE_INFLUENCERS > 0
  5. // having bone influencers implies you have bones
  6. uniform mat4 mBones[BonesPerMesh];
  7. attribute vec4 matricesIndices;
  8. attribute vec4 matricesWeights;
  9. #if NUM_BONE_INFLUENCERS > 4
  10. attribute vec4 matricesIndicesExtra;
  11. attribute vec4 matricesWeightsExtra;
  12. #endif
  13. #endif
  14. // Uniform
  15. #ifdef INSTANCES
  16. attribute vec4 world0;
  17. attribute vec4 world1;
  18. attribute vec4 world2;
  19. attribute vec4 world3;
  20. #else
  21. uniform mat4 world;
  22. #endif
  23. uniform mat4 viewProjection;
  24. varying vec4 vPosition;
  25. #ifdef ALPHATEST
  26. varying vec2 vUV;
  27. uniform mat4 diffuseMatrix;
  28. #ifdef UV1
  29. attribute vec2 uv;
  30. #endif
  31. #ifdef UV2
  32. attribute vec2 uv2;
  33. #endif
  34. #endif
  35. void main(void)
  36. {
  37. #ifdef INSTANCES
  38. mat4 finalWorld = mat4(world0, world1, world2, world3);
  39. #else
  40. mat4 finalWorld = world;
  41. #endif
  42. #if NUM_BONE_INFLUENCERS > 0
  43. mat4 influence;
  44. influence = mBones[int(matricesIndices[0])] * matricesWeights[0];
  45. #if NUM_BONE_INFLUENCERS > 1
  46. influence += mBones[int(matricesIndices[1])] * matricesWeights[1];
  47. #endif
  48. #if NUM_BONE_INFLUENCERS > 2
  49. influence += mBones[int(matricesIndices[2])] * matricesWeights[2];
  50. #endif
  51. #if NUM_BONE_INFLUENCERS > 3
  52. influence += mBones[int(matricesIndices[3])] * matricesWeights[3];
  53. #endif
  54. #if NUM_BONE_INFLUENCERS > 4
  55. influence += mBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];
  56. #endif
  57. #if NUM_BONE_INFLUENCERS > 5
  58. influence += mBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];
  59. #endif
  60. #if NUM_BONE_INFLUENCERS > 6
  61. influence += mBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];
  62. #endif
  63. #if NUM_BONE_INFLUENCERS > 7
  64. influence += mBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];
  65. #endif
  66. finalWorld = finalWorld * influence;
  67. #endif
  68. #ifdef CUBEMAP
  69. vPosition = finalWorld * vec4(position, 1.0);
  70. gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
  71. #else
  72. vPosition = viewProjection * finalWorld * vec4(position, 1.0);
  73. gl_Position = vPosition;
  74. #endif
  75. #ifdef ALPHATEST
  76. #ifdef UV1
  77. vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
  78. #endif
  79. #ifdef UV2
  80. vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
  81. #endif
  82. #endif
  83. }