default.vertex.fx 4.3 KB

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