textured.vert 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #ifndef DIRECTIONAL_LIGHT_COUNT
  2. #define DIRECTIONAL_LIGHT_COUNT 0
  3. #endif
  4. #ifndef SPOT_LIGHT_COUNT
  5. #define SPOT_LIGHT_COUNT 0
  6. #endif
  7. #ifndef POINT_LIGHT_COUNT
  8. #define POINT_LIGHT_COUNT 0
  9. #endif
  10. #if (DIRECTIONAL_LIGHT_COUNT > 0) || (POINT_LIGHT_COUNT > 0) || (SPOT_LIGHT_COUNT > 0)
  11. #define LIGHTING
  12. #endif
  13. ///////////////////////////////////////////////////////////
  14. // Atributes
  15. attribute vec4 a_position;
  16. #if defined(SKINNING)
  17. attribute vec4 a_blendWeights;
  18. attribute vec4 a_blendIndices;
  19. #endif
  20. attribute vec2 a_texCoord;
  21. #if defined(LIGHTMAP)
  22. attribute vec2 a_texCoord1;
  23. #endif
  24. #if defined(LIGHTING)
  25. attribute vec3 a_normal;
  26. #if defined(BUMPED)
  27. attribute vec3 a_tangent;
  28. attribute vec3 a_binormal;
  29. #endif
  30. #endif
  31. ///////////////////////////////////////////////////////////
  32. // Uniforms
  33. uniform mat4 u_worldViewProjectionMatrix;
  34. #if defined(SKINNING)
  35. uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3];
  36. #endif
  37. #if defined(LIGHTING)
  38. uniform mat4 u_inverseTransposeWorldViewMatrix;
  39. #if defined(SPECULAR) || (POINT_LIGHT_COUNT > 0) || (SPOT_LIGHT_COUNT > 0)
  40. uniform mat4 u_worldViewMatrix;
  41. #endif
  42. #if defined(BUMPED) && (DIRECTIONAL_LIGHT_COUNT > 0)
  43. uniform vec3 u_directionalLightDirection[DIRECTIONAL_LIGHT_COUNT];
  44. #endif
  45. #if (POINT_LIGHT_COUNT > 0)
  46. uniform vec3 u_pointLightPosition[POINT_LIGHT_COUNT];
  47. #endif
  48. #if (SPOT_LIGHT_COUNT > 0)
  49. uniform vec3 u_spotLightPosition[SPOT_LIGHT_COUNT];
  50. #if defined(BUMPED)
  51. uniform vec3 u_spotLightDirection[SPOT_LIGHT_COUNT];
  52. #endif
  53. #endif
  54. #if defined(SPECULAR)
  55. uniform vec3 u_cameraPosition;
  56. #endif
  57. #endif
  58. #if defined(TEXTURE_REPEAT)
  59. uniform vec2 u_textureRepeat;
  60. #endif
  61. #if defined(TEXTURE_OFFSET)
  62. uniform vec2 u_textureOffset;
  63. #endif
  64. #if defined(CLIP_PLANE)
  65. uniform mat4 u_worldMatrix;
  66. uniform vec4 u_clipPlane;
  67. #endif
  68. ///////////////////////////////////////////////////////////
  69. // Varyings
  70. varying vec2 v_texCoord;
  71. #if defined(LIGHTMAP)
  72. varying vec2 v_texCoord1;
  73. #endif
  74. #if defined(LIGHTING)
  75. #if !defined(BUMPED)
  76. varying vec3 v_normalVector;
  77. #endif
  78. #if defined(BUMPED) && (DIRECTIONAL_LIGHT_COUNT > 0)
  79. varying vec3 v_directionalLightDirection[DIRECTIONAL_LIGHT_COUNT];
  80. #endif
  81. #if (POINT_LIGHT_COUNT > 0)
  82. varying vec3 v_vertexToPointLightDirection[POINT_LIGHT_COUNT];
  83. #endif
  84. #if (SPOT_LIGHT_COUNT > 0)
  85. varying vec3 v_vertexToSpotLightDirection[SPOT_LIGHT_COUNT];
  86. #if defined(BUMPED)
  87. varying vec3 v_spotLightDirection[SPOT_LIGHT_COUNT];
  88. #endif
  89. #endif
  90. #if defined(SPECULAR)
  91. varying vec3 v_cameraDirection;
  92. #endif
  93. #include "lighting.vert"
  94. #endif
  95. #if defined(SKINNING)
  96. #include "skinning.vert"
  97. #else
  98. #include "skinning-none.vert"
  99. #endif
  100. #if defined(CLIP_PLANE)
  101. varying float v_clipDistance;
  102. #endif
  103. void main()
  104. {
  105. vec4 position = getPosition();
  106. gl_Position = u_worldViewProjectionMatrix * position;
  107. #if defined(LIGHTING)
  108. vec3 normal = getNormal();
  109. // Transform the normal, tangent and binormals to view space.
  110. mat3 inverseTransposeWorldViewMatrix = mat3(u_inverseTransposeWorldViewMatrix[0].xyz, u_inverseTransposeWorldViewMatrix[1].xyz, u_inverseTransposeWorldViewMatrix[2].xyz);
  111. vec3 normalVector = normalize(inverseTransposeWorldViewMatrix * normal);
  112. #if defined(BUMPED)
  113. vec3 tangent = getTangent();
  114. vec3 binormal = getBinormal();
  115. vec3 tangentVector = normalize(inverseTransposeWorldViewMatrix * tangent);
  116. vec3 binormalVector = normalize(inverseTransposeWorldViewMatrix * binormal);
  117. mat3 tangentSpaceTransformMatrix = mat3(tangentVector.x, binormalVector.x, normalVector.x, tangentVector.y, binormalVector.y, normalVector.y, tangentVector.z, binormalVector.z, normalVector.z);
  118. applyLight(position, tangentSpaceTransformMatrix);
  119. #else
  120. v_normalVector = normalVector;
  121. applyLight(position);
  122. #endif
  123. #endif
  124. v_texCoord = a_texCoord;
  125. #if defined(TEXTURE_REPEAT)
  126. v_texCoord *= u_textureRepeat;
  127. #endif
  128. #if defined(TEXTURE_OFFSET)
  129. v_texCoord += u_textureOffset;
  130. #endif
  131. #if defined(LIGHTMAP)
  132. v_texCoord1 = a_texCoord1;
  133. #endif
  134. #if defined(CLIP_PLANE)
  135. v_clipDistance = dot(u_worldMatrix * position, u_clipPlane);
  136. #endif
  137. }