default.vertex.fx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. #include<__decl__defaultVertex>
  2. // Attributes
  3. #define CUSTOM_VERTEX_BEGIN
  4. attribute vec3 position;
  5. #ifdef NORMAL
  6. attribute vec3 normal;
  7. #endif
  8. #ifdef TANGENT
  9. attribute vec4 tangent;
  10. #endif
  11. #ifdef UV1
  12. attribute vec2 uv;
  13. #endif
  14. #ifdef UV2
  15. attribute vec2 uv2;
  16. #endif
  17. #ifdef VERTEXCOLOR
  18. attribute vec4 color;
  19. #endif
  20. #include<helperFunctions>
  21. #include<bonesDeclaration>
  22. // Uniforms
  23. #include<instancesDeclaration>
  24. #include<prePassVertexDeclaration>
  25. #ifdef MAINUV1
  26. varying vec2 vMainUV1;
  27. #endif
  28. #ifdef MAINUV2
  29. varying vec2 vMainUV2;
  30. #endif
  31. #if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0
  32. varying vec2 vDiffuseUV;
  33. #endif
  34. #if defined(DETAIL) && DETAILDIRECTUV == 0
  35. varying vec2 vDetailUV;
  36. #endif
  37. #if defined(AMBIENT) && AMBIENTDIRECTUV == 0
  38. varying vec2 vAmbientUV;
  39. #endif
  40. #if defined(OPACITY) && OPACITYDIRECTUV == 0
  41. varying vec2 vOpacityUV;
  42. #endif
  43. #if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0
  44. varying vec2 vEmissiveUV;
  45. #endif
  46. #if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0
  47. varying vec2 vLightmapUV;
  48. #endif
  49. #if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0
  50. varying vec2 vSpecularUV;
  51. #endif
  52. #if defined(BUMP) && BUMPDIRECTUV == 0
  53. varying vec2 vBumpUV;
  54. #endif
  55. // Output
  56. varying vec3 vPositionW;
  57. #ifdef NORMAL
  58. varying vec3 vNormalW;
  59. #endif
  60. #ifdef VERTEXCOLOR
  61. varying vec4 vColor;
  62. #endif
  63. #include<bumpVertexDeclaration>
  64. #include<clipPlaneVertexDeclaration>
  65. #include<fogVertexDeclaration>
  66. #include<__decl__lightFragment>[0..maxSimultaneousLights]
  67. #include<morphTargetsVertexGlobalDeclaration>
  68. #include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]
  69. #ifdef REFLECTIONMAP_SKYBOX
  70. varying vec3 vPositionUVW;
  71. #endif
  72. #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
  73. varying vec3 vDirectionW;
  74. #endif
  75. #include<logDepthDeclaration>
  76. #define CUSTOM_VERTEX_DEFINITIONS
  77. void main(void) {
  78. #define CUSTOM_VERTEX_MAIN_BEGIN
  79. vec3 positionUpdated = position;
  80. #ifdef NORMAL
  81. vec3 normalUpdated = normal;
  82. #endif
  83. #ifdef TANGENT
  84. vec4 tangentUpdated = tangent;
  85. #endif
  86. #ifdef UV1
  87. vec2 uvUpdated = uv;
  88. #endif
  89. #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
  90. #ifdef REFLECTIONMAP_SKYBOX
  91. vPositionUVW = positionUpdated;
  92. #endif
  93. #define CUSTOM_VERTEX_UPDATE_POSITION
  94. #define CUSTOM_VERTEX_UPDATE_NORMAL
  95. #include<instancesVertex>
  96. #if defined(PREPASS) && defined(PREPASS_VELOCITY) && !defined(BONES_VELOCITY_ENABLED)
  97. // Compute velocity before bones computation
  98. vCurrentPosition = viewProjection * finalWorld * vec4(positionUpdated, 1.0);
  99. vPreviousPosition = previousViewProjection * previousWorld * vec4(positionUpdated, 1.0);
  100. #endif
  101. #include<bonesVertex>
  102. vec4 worldPos = finalWorld * vec4(positionUpdated, 1.0);
  103. #ifdef NORMAL
  104. mat3 normalWorld = mat3(finalWorld);
  105. #if defined(INSTANCES) && defined(THIN_INSTANCES)
  106. vNormalW = normalUpdated / vec3(dot(normalWorld[0], normalWorld[0]), dot(normalWorld[1], normalWorld[1]), dot(normalWorld[2], normalWorld[2]));
  107. vNormalW = normalize(normalWorld * vNormalW);
  108. #else
  109. #ifdef NONUNIFORMSCALING
  110. normalWorld = transposeMat3(inverseMat3(normalWorld));
  111. #endif
  112. vNormalW = normalize(normalWorld * normalUpdated);
  113. #endif
  114. #endif
  115. #define CUSTOM_VERTEX_UPDATE_WORLDPOS
  116. #ifdef MULTIVIEW
  117. if (gl_ViewID_OVR == 0u) {
  118. gl_Position = viewProjection * worldPos;
  119. } else {
  120. gl_Position = viewProjectionR * worldPos;
  121. }
  122. #else
  123. gl_Position = viewProjection * worldPos;
  124. #endif
  125. vPositionW = vec3(worldPos);
  126. #include<prePassVertex>
  127. #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
  128. vDirectionW = normalize(vec3(finalWorld * vec4(positionUpdated, 0.0)));
  129. #endif
  130. // Texture coordinates
  131. #ifndef UV1
  132. vec2 uvUpdated = vec2(0., 0.);
  133. #endif
  134. #ifndef UV2
  135. vec2 uv2 = vec2(0., 0.);
  136. #endif
  137. #ifdef MAINUV1
  138. vMainUV1 = uvUpdated;
  139. #endif
  140. #ifdef MAINUV2
  141. vMainUV2 = uv2;
  142. #endif
  143. #if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0
  144. if (vDiffuseInfos.x == 0.)
  145. {
  146. vDiffuseUV = vec2(diffuseMatrix * vec4(uvUpdated, 1.0, 0.0));
  147. }
  148. else
  149. {
  150. vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
  151. }
  152. #endif
  153. #if defined(DETAIL) && DETAILDIRECTUV == 0
  154. if (vDetailInfos.x == 0.)
  155. {
  156. vDetailUV = vec2(detailMatrix * vec4(uvUpdated, 1.0, 0.0));
  157. }
  158. else
  159. {
  160. vDetailUV = vec2(detailMatrix * vec4(uv2, 1.0, 0.0));
  161. }
  162. #endif
  163. #if defined(AMBIENT) && AMBIENTDIRECTUV == 0
  164. if (vAmbientInfos.x == 0.)
  165. {
  166. vAmbientUV = vec2(ambientMatrix * vec4(uvUpdated, 1.0, 0.0));
  167. }
  168. else
  169. {
  170. vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));
  171. }
  172. #endif
  173. #if defined(OPACITY) && OPACITYDIRECTUV == 0
  174. if (vOpacityInfos.x == 0.)
  175. {
  176. vOpacityUV = vec2(opacityMatrix * vec4(uvUpdated, 1.0, 0.0));
  177. }
  178. else
  179. {
  180. vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));
  181. }
  182. #endif
  183. #if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0
  184. if (vEmissiveInfos.x == 0.)
  185. {
  186. vEmissiveUV = vec2(emissiveMatrix * vec4(uvUpdated, 1.0, 0.0));
  187. }
  188. else
  189. {
  190. vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));
  191. }
  192. #endif
  193. #if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0
  194. if (vLightmapInfos.x == 0.)
  195. {
  196. vLightmapUV = vec2(lightmapMatrix * vec4(uvUpdated, 1.0, 0.0));
  197. }
  198. else
  199. {
  200. vLightmapUV = vec2(lightmapMatrix * vec4(uv2, 1.0, 0.0));
  201. }
  202. #endif
  203. #if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0
  204. if (vSpecularInfos.x == 0.)
  205. {
  206. vSpecularUV = vec2(specularMatrix * vec4(uvUpdated, 1.0, 0.0));
  207. }
  208. else
  209. {
  210. vSpecularUV = vec2(specularMatrix * vec4(uv2, 1.0, 0.0));
  211. }
  212. #endif
  213. #if defined(BUMP) && BUMPDIRECTUV == 0
  214. if (vBumpInfos.x == 0.)
  215. {
  216. vBumpUV = vec2(bumpMatrix * vec4(uvUpdated, 1.0, 0.0));
  217. }
  218. else
  219. {
  220. vBumpUV = vec2(bumpMatrix * vec4(uv2, 1.0, 0.0));
  221. }
  222. #endif
  223. #include<bumpVertex>
  224. #include<clipPlaneVertex>
  225. #include<fogVertex>
  226. #include<shadowsVertex>[0..maxSimultaneousLights]
  227. #ifdef VERTEXCOLOR
  228. // Vertex color
  229. vColor = color;
  230. #endif
  231. #include<pointCloudVertex>
  232. #include<logDepthVertex>
  233. #define CUSTOM_VERTEX_MAIN_END
  234. }