default.vertex.fx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #ifdef GL_ES
  2. precision highp float;
  3. #endif
  4. // Attributes
  5. attribute vec3 position;
  6. attribute vec3 normal;
  7. #ifdef UV1
  8. attribute vec2 uv;
  9. #endif
  10. #ifdef UV2
  11. attribute vec2 uv2;
  12. #endif
  13. #ifdef VERTEXCOLOR
  14. attribute vec3 color;
  15. #endif
  16. #ifdef BONES
  17. attribute vec4 matricesIndices;
  18. attribute vec4 matricesWeights;
  19. #endif
  20. // Uniforms
  21. #ifdef INSTANCES
  22. attribute vec4 world0;
  23. attribute vec4 world1;
  24. attribute vec4 world2;
  25. attribute vec4 world3;
  26. #else
  27. uniform mat4 world;
  28. #endif
  29. uniform mat4 view;
  30. uniform mat4 viewProjection;
  31. #ifdef DIFFUSE
  32. varying vec2 vDiffuseUV;
  33. uniform mat4 diffuseMatrix;
  34. uniform vec2 vDiffuseInfos;
  35. #endif
  36. #ifdef AMBIENT
  37. varying vec2 vAmbientUV;
  38. uniform mat4 ambientMatrix;
  39. uniform vec2 vAmbientInfos;
  40. #endif
  41. #ifdef OPACITY
  42. varying vec2 vOpacityUV;
  43. uniform mat4 opacityMatrix;
  44. uniform vec2 vOpacityInfos;
  45. #endif
  46. #ifdef EMISSIVE
  47. varying vec2 vEmissiveUV;
  48. uniform vec2 vEmissiveInfos;
  49. uniform mat4 emissiveMatrix;
  50. #endif
  51. #ifdef SPECULAR
  52. varying vec2 vSpecularUV;
  53. uniform vec2 vSpecularInfos;
  54. uniform mat4 specularMatrix;
  55. #endif
  56. #ifdef BUMP
  57. varying vec2 vBumpUV;
  58. uniform vec2 vBumpInfos;
  59. uniform mat4 bumpMatrix;
  60. #endif
  61. #ifdef BONES
  62. uniform mat4 mBones[BonesPerMesh];
  63. #endif
  64. // Output
  65. varying vec3 vPositionW;
  66. varying vec3 vNormalW;
  67. #ifdef VERTEXCOLOR
  68. varying vec3 vColor;
  69. #endif
  70. #ifdef CLIPPLANE
  71. uniform vec4 vClipPlane;
  72. varying float fClipDistance;
  73. #endif
  74. #ifdef FOG
  75. varying float fFogDistance;
  76. #endif
  77. #ifdef SHADOWS
  78. #ifdef LIGHT0
  79. uniform mat4 lightMatrix0;
  80. varying vec4 vPositionFromLight0;
  81. #endif
  82. #ifdef LIGHT1
  83. uniform mat4 lightMatrix1;
  84. varying vec4 vPositionFromLight1;
  85. #endif
  86. #ifdef LIGHT2
  87. uniform mat4 lightMatrix2;
  88. varying vec4 vPositionFromLight2;
  89. #endif
  90. #ifdef LIGHT3
  91. uniform mat4 lightMatrix3;
  92. varying vec4 vPositionFromLight3;
  93. #endif
  94. #endif
  95. #ifdef REFLECTION
  96. varying vec3 vPositionUVW;
  97. #endif
  98. void main(void) {
  99. mat4 finalWorld;
  100. #ifdef REFLECTION
  101. vPositionUVW = position;
  102. #endif
  103. #ifdef BONES
  104. mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;
  105. mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;
  106. mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;
  107. #ifdef BONES4
  108. mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;
  109. finalWorld = world * (m0 + m1 + m2 + m3);
  110. #else
  111. finalWorld = world * (m0 + m1 + m2);
  112. #endif
  113. #else
  114. #ifdef INSTANCES
  115. finalWorld = mat4(world0, world1, world2, world3);
  116. #else
  117. finalWorld = world;
  118. #endif
  119. #endif
  120. gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
  121. vec4 worldPos = finalWorld * vec4(position, 1.0);
  122. vPositionW = vec3(worldPos);
  123. vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
  124. // Texture coordinates
  125. #ifndef UV1
  126. vec2 uv = vec2(0., 0.);
  127. #endif
  128. #ifndef UV2
  129. vec2 uv2 = vec2(0., 0.);
  130. #endif
  131. #ifdef DIFFUSE
  132. if (vDiffuseInfos.x == 0.)
  133. {
  134. vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
  135. }
  136. else
  137. {
  138. vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
  139. }
  140. #endif
  141. #ifdef AMBIENT
  142. if (vAmbientInfos.x == 0.)
  143. {
  144. vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));
  145. }
  146. else
  147. {
  148. vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));
  149. }
  150. #endif
  151. #ifdef OPACITY
  152. if (vOpacityInfos.x == 0.)
  153. {
  154. vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));
  155. }
  156. else
  157. {
  158. vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));
  159. }
  160. #endif
  161. #ifdef EMISSIVE
  162. if (vEmissiveInfos.x == 0.)
  163. {
  164. vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));
  165. }
  166. else
  167. {
  168. vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));
  169. }
  170. #endif
  171. #ifdef SPECULAR
  172. if (vSpecularInfos.x == 0.)
  173. {
  174. vSpecularUV = vec2(specularMatrix * vec4(uv, 1.0, 0.0));
  175. }
  176. else
  177. {
  178. vSpecularUV = vec2(specularMatrix * vec4(uv2, 1.0, 0.0));
  179. }
  180. #endif
  181. #ifdef BUMP
  182. if (vBumpInfos.x == 0.)
  183. {
  184. vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));
  185. }
  186. else
  187. {
  188. vBumpUV = vec2(bumpMatrix * vec4(uv2, 1.0, 0.0));
  189. }
  190. #endif
  191. // Clip plane
  192. #ifdef CLIPPLANE
  193. fClipDistance = dot(worldPos, vClipPlane);
  194. #endif
  195. // Fog
  196. #ifdef FOG
  197. fFogDistance = (view * worldPos).z;
  198. #endif
  199. // Shadows
  200. #ifdef SHADOWS
  201. #ifdef LIGHT0
  202. vPositionFromLight0 = lightMatrix0 * worldPos;
  203. #endif
  204. #ifdef LIGHT1
  205. vPositionFromLight1 = lightMatrix1 * worldPos;
  206. #endif
  207. #ifdef LIGHT2
  208. vPositionFromLight2 = lightMatrix2 * worldPos;
  209. #endif
  210. #ifdef LIGHT3
  211. vPositionFromLight3 = lightMatrix3 * worldPos;
  212. #endif
  213. #endif
  214. // Vertex color
  215. #ifdef VERTEXCOLOR
  216. vColor = color;
  217. #endif
  218. }