geometry.vertex.fx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. precision highp float;
  2. precision highp int;
  3. #include<bonesDeclaration>
  4. #include<morphTargetsVertexGlobalDeclaration>
  5. #include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]
  6. #include<instancesDeclaration>
  7. attribute vec3 position;
  8. attribute vec3 normal;
  9. #if defined(ALPHATEST) || defined(NEED_UV)
  10. varying vec2 vUV;
  11. uniform mat4 diffuseMatrix;
  12. #ifdef UV1
  13. attribute vec2 uv;
  14. #endif
  15. #ifdef UV2
  16. attribute vec2 uv2;
  17. #endif
  18. #endif
  19. // Uniform
  20. uniform mat4 viewProjection;
  21. uniform mat4 view;
  22. varying vec3 vNormalV;
  23. varying vec4 vViewPos;
  24. #ifdef POSITION
  25. varying vec3 vPosition;
  26. #endif
  27. #ifdef VELOCITY
  28. uniform mat4 previousWorld;
  29. uniform mat4 previousViewProjection;
  30. #ifdef BONES_VELOCITY_ENABLED
  31. #if NUM_BONE_INFLUENCERS > 0
  32. uniform mat4 mPreviousBones[BonesPerMesh];
  33. #endif
  34. #endif
  35. varying vec4 vCurrentPosition;
  36. varying vec4 vPreviousPosition;
  37. #endif
  38. void main(void)
  39. {
  40. vec3 positionUpdated = position;
  41. vec3 normalUpdated = normal;
  42. #ifdef UV1
  43. vec2 uvUpdated = uv;
  44. #endif
  45. #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
  46. #include<instancesVertex>
  47. #if defined(VELOCITY) && !defined(BONES_VELOCITY_ENABLED)
  48. // Compute velocity before bones computation
  49. vCurrentPosition = viewProjection * finalWorld * vec4(positionUpdated, 1.0);
  50. vPreviousPosition = previousViewProjection * previousWorld * vec4(positionUpdated, 1.0);
  51. #endif
  52. #include<bonesVertex>
  53. vec4 pos = vec4(finalWorld * vec4(positionUpdated, 1.0));
  54. vNormalV = normalize(vec3((view * finalWorld) * vec4(normalUpdated, 0.0)));
  55. vViewPos = view * pos;
  56. #if defined(VELOCITY) && defined(BONES_VELOCITY_ENABLED)
  57. vCurrentPosition = viewProjection * finalWorld * vec4(positionUpdated, 1.0);
  58. #if NUM_BONE_INFLUENCERS > 0
  59. mat4 previousInfluence;
  60. previousInfluence = mPreviousBones[int(matricesIndices[0])] * matricesWeights[0];
  61. #if NUM_BONE_INFLUENCERS > 1
  62. previousInfluence += mPreviousBones[int(matricesIndices[1])] * matricesWeights[1];
  63. #endif
  64. #if NUM_BONE_INFLUENCERS > 2
  65. previousInfluence += mPreviousBones[int(matricesIndices[2])] * matricesWeights[2];
  66. #endif
  67. #if NUM_BONE_INFLUENCERS > 3
  68. previousInfluence += mPreviousBones[int(matricesIndices[3])] * matricesWeights[3];
  69. #endif
  70. #if NUM_BONE_INFLUENCERS > 4
  71. previousInfluence += mPreviousBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];
  72. #endif
  73. #if NUM_BONE_INFLUENCERS > 5
  74. previousInfluence += mPreviousBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];
  75. #endif
  76. #if NUM_BONE_INFLUENCERS > 6
  77. previousInfluence += mPreviousBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];
  78. #endif
  79. #if NUM_BONE_INFLUENCERS > 7
  80. previousInfluence += mPreviousBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];
  81. #endif
  82. vPreviousPosition = previousViewProjection * previousWorld * previousInfluence * vec4(positionUpdated, 1.0);
  83. #else
  84. vPreviousPosition = previousViewProjection * previousWorld * vec4(positionUpdated, 1.0);
  85. #endif
  86. #endif
  87. #ifdef POSITION
  88. vPosition = pos.xyz / pos.w;
  89. #endif
  90. gl_Position = viewProjection * finalWorld * vec4(positionUpdated, 1.0);
  91. #if defined(ALPHATEST) || defined(BASIC_RENDER)
  92. #ifdef UV1
  93. vUV = vec2(diffuseMatrix * vec4(uvUpdated, 1.0, 0.0));
  94. #endif
  95. #ifdef UV2
  96. vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
  97. #endif
  98. #endif
  99. }