legacypbr.vertex.fx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. precision mediump float;
  2. // Attributes
  3. attribute vec3 position;
  4. attribute vec3 normal;
  5. #ifdef UV1
  6. attribute vec2 uv;
  7. #endif
  8. #ifdef UV2
  9. attribute vec2 uv2;
  10. #endif
  11. #ifdef VERTEXCOLOR
  12. attribute vec4 color;
  13. #endif
  14. #if NUM_BONE_INFLUENCERS > 0
  15. uniform mat4 mBones[BonesPerMesh];
  16. attribute vec4 matricesIndices;
  17. attribute vec4 matricesWeights;
  18. #if NUM_BONE_INFLUENCERS > 4
  19. attribute vec4 matricesIndicesExtra;
  20. attribute vec4 matricesWeightsExtra;
  21. #endif
  22. #endif
  23. // Uniforms
  24. uniform mat4 world;
  25. uniform mat4 view;
  26. uniform mat4 viewProjection;
  27. #ifdef ALBEDO
  28. varying vec2 vAlbedoUV;
  29. uniform mat4 albedoMatrix;
  30. uniform vec2 vAlbedoInfos;
  31. #endif
  32. #ifdef AMBIENT
  33. varying vec2 vAmbientUV;
  34. uniform mat4 ambientMatrix;
  35. uniform vec2 vAmbientInfos;
  36. #endif
  37. #ifdef OPACITY
  38. varying vec2 vOpacityUV;
  39. uniform mat4 opacityMatrix;
  40. uniform vec2 vOpacityInfos;
  41. #endif
  42. #ifdef EMISSIVE
  43. varying vec2 vEmissiveUV;
  44. uniform vec2 vEmissiveInfos;
  45. uniform mat4 emissiveMatrix;
  46. #endif
  47. #if defined(REFLECTIVITY)
  48. varying vec2 vReflectivityUV;
  49. uniform vec2 vReflectivityInfos;
  50. uniform mat4 reflectivityMatrix;
  51. #endif
  52. // Output
  53. varying vec3 vPositionW;
  54. varying vec3 vNormalW;
  55. #ifdef VERTEXCOLOR
  56. varying vec4 vColor;
  57. #endif
  58. #ifdef CLIPPLANE
  59. uniform vec4 vClipPlane;
  60. varying float fClipDistance;
  61. #endif
  62. void main(void) {
  63. mat4 finalWorld = world;
  64. #if NUM_BONE_INFLUENCERS > 0
  65. mat4 influence;
  66. influence = mBones[int(matricesIndices[0])] * matricesWeights[0];
  67. #if NUM_BONE_INFLUENCERS > 1
  68. influence += mBones[int(matricesIndices[1])] * matricesWeights[1];
  69. #endif
  70. #if NUM_BONE_INFLUENCERS > 2
  71. influence += mBones[int(matricesIndices[2])] * matricesWeights[2];
  72. #endif
  73. #if NUM_BONE_INFLUENCERS > 3
  74. influence += mBones[int(matricesIndices[3])] * matricesWeights[3];
  75. #endif
  76. #if NUM_BONE_INFLUENCERS > 4
  77. influence += mBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];
  78. #endif
  79. #if NUM_BONE_INFLUENCERS > 5
  80. influence += mBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];
  81. #endif
  82. #if NUM_BONE_INFLUENCERS > 6
  83. influence += mBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];
  84. #endif
  85. #if NUM_BONE_INFLUENCERS > 7
  86. influence += mBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];
  87. #endif
  88. finalWorld = finalWorld * influence;
  89. #endif
  90. gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
  91. vec4 worldPos = finalWorld * vec4(position, 1.0);
  92. vPositionW = vec3(worldPos);
  93. vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
  94. // Texture coordinates
  95. #ifndef UV1
  96. vec2 uv = vec2(0., 0.);
  97. #endif
  98. #ifndef UV2
  99. vec2 uv2 = vec2(0., 0.);
  100. #endif
  101. #ifdef ALBEDO
  102. if (vAlbedoInfos.x == 0.)
  103. {
  104. vAlbedoUV = vec2(albedoMatrix * vec4(uv, 1.0, 0.0));
  105. }
  106. else
  107. {
  108. vAlbedoUV = vec2(albedoMatrix * vec4(uv2, 1.0, 0.0));
  109. }
  110. #endif
  111. #ifdef AMBIENT
  112. if (vAmbientInfos.x == 0.)
  113. {
  114. vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));
  115. }
  116. else
  117. {
  118. vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));
  119. }
  120. #endif
  121. #ifdef OPACITY
  122. if (vOpacityInfos.x == 0.)
  123. {
  124. vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));
  125. }
  126. else
  127. {
  128. vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));
  129. }
  130. #endif
  131. #ifdef EMISSIVE
  132. if (vEmissiveInfos.x == 0.)
  133. {
  134. vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));
  135. }
  136. else
  137. {
  138. vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));
  139. }
  140. #endif
  141. #if defined(REFLECTIVITY)
  142. if (vReflectivityInfos.x == 0.)
  143. {
  144. vReflectivityUV = vec2(reflectivityMatrix * vec4(uv, 1.0, 0.0));
  145. }
  146. else
  147. {
  148. vReflectivityUV = vec2(reflectivityMatrix * vec4(uv2, 1.0, 0.0));
  149. }
  150. #endif
  151. // Clip plane
  152. #ifdef CLIPPLANE
  153. fClipDistance = dot(worldPos, vClipPlane);
  154. #endif
  155. // Vertex color
  156. #ifdef VERTEXCOLOR
  157. vColor = color;
  158. #endif
  159. }