您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

115 行
2.5 KiB

  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. // Attributes
  15. attribute vec4 a_position;
  16. #if !defined(NORMAL_MAP) && defined(LIGHTING)
  17. attribute vec3 a_normal;
  18. #endif
  19. attribute vec2 a_texCoord0;
  20. ///////////////////////////////////////////////////////////
  21. // Uniforms
  22. uniform mat4 u_worldViewProjectionMatrix;
  23. #if !defined(NORMAL_MAP) && defined(LIGHTING)
  24. uniform mat4 u_normalMatrix;
  25. #endif
  26. #if defined(LIGHTING)
  27. uniform mat4 u_inverseTransposeWorldViewMatrix;
  28. #if (POINT_LIGHT_COUNT > 0) || (SPOT_LIGHT_COUNT > 0)
  29. uniform mat4 u_worldViewMatrix;
  30. #endif
  31. #if (DIRECTIONAL_LIGHT_COUNT > 0)
  32. uniform vec3 u_directionalLightDirection[DIRECTIONAL_LIGHT_COUNT];
  33. #endif
  34. #if (POINT_LIGHT_COUNT > 0)
  35. uniform vec3 u_pointLightPosition[POINT_LIGHT_COUNT];
  36. #endif
  37. #if (SPOT_LIGHT_COUNT > 0)
  38. uniform vec3 u_spotLightPosition[SPOT_LIGHT_COUNT];
  39. uniform vec3 u_spotLightDirection[SPOT_LIGHT_COUNT];
  40. #endif
  41. #endif
  42. ///////////////////////////////////////////////////////////
  43. // Varyings
  44. #if defined(LIGHTING)
  45. varying vec3 v_normalVector;
  46. #if (DIRECTIONAL_LIGHT_COUNT > 0)
  47. varying vec3 v_lightDirection[DIRECTIONAL_LIGHT_COUNT];
  48. #endif
  49. #if (POINT_LIGHT_COUNT > 0)
  50. varying vec3 v_vertexToPointLightDirection[POINT_LIGHT_COUNT];
  51. #endif
  52. #if (SPOT_LIGHT_COUNT > 0)
  53. varying vec3 v_vertexToSpotLightDirection[SPOT_LIGHT_COUNT];
  54. #endif
  55. #include "lighting.vert"
  56. #endif
  57. varying vec2 v_texCoord0;
  58. #if LAYER_COUNT > 0
  59. varying vec2 v_texCoordLayer0;
  60. #endif
  61. #if LAYER_COUNT > 1
  62. varying vec2 v_texCoordLayer1;
  63. #endif
  64. #if LAYER_COUNT > 2
  65. varying vec2 v_texCoordLayer2;
  66. #endif
  67. void main()
  68. {
  69. // Transform position to clip space.
  70. gl_Position = u_worldViewProjectionMatrix * a_position;
  71. #if defined(LIGHTING)
  72. #if !defined(NORMAL_MAP)
  73. v_normalVector = normalize((u_normalMatrix * vec4(a_normal.x, a_normal.y, a_normal.z, 0)).xyz);
  74. #endif
  75. applyLight(a_position);
  76. #endif
  77. // Pass base texture coord
  78. v_texCoord0 = a_texCoord0;
  79. // Pass repeated texture coordinates for each layer
  80. #if LAYER_COUNT > 0
  81. v_texCoordLayer0 = a_texCoord0 * TEXTURE_REPEAT_0;
  82. #endif
  83. #if LAYER_COUNT > 1
  84. v_texCoordLayer1 = a_texCoord0 * TEXTURE_REPEAT_1;
  85. #endif
  86. #if LAYER_COUNT > 2
  87. v_texCoordLayer2 = a_texCoord0 * TEXTURE_REPEAT_2;
  88. #endif
  89. }