simple.vertex.fx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. precision highp float;
  2. // Attributes
  3. attribute vec3 position;
  4. #ifdef NORMAL
  5. attribute vec3 normal;
  6. #endif
  7. #ifdef UV1
  8. attribute vec2 uv;
  9. #endif
  10. #ifdef UV2
  11. attribute vec2 uv2;
  12. #endif
  13. #ifdef VERTEXCOLOR
  14. attribute vec4 color;
  15. #endif
  16. #include<bonesDeclaration>
  17. // Uniforms
  18. #include<instancesDeclaration>
  19. uniform mat4 view;
  20. uniform mat4 viewProjection;
  21. #ifdef DIFFUSE
  22. varying vec2 vDiffuseUV;
  23. uniform mat4 diffuseMatrix;
  24. uniform vec2 vDiffuseInfos;
  25. #endif
  26. #ifdef POINTSIZE
  27. uniform float pointSize;
  28. #endif
  29. // Output
  30. varying vec3 vPositionW;
  31. #ifdef NORMAL
  32. varying vec3 vNormalW;
  33. #endif
  34. #ifdef VERTEXCOLOR
  35. varying vec4 vColor;
  36. #endif
  37. #ifdef CLIPPLANE
  38. uniform vec4 vClipPlane;
  39. varying float fClipDistance;
  40. #endif
  41. #include<fogVertexDeclaration>
  42. #ifdef SHADOWS
  43. #if defined(SPOTLIGHT0) || defined(DIRLIGHT0)
  44. uniform mat4 lightMatrix0;
  45. varying vec4 vPositionFromLight0;
  46. #endif
  47. #if defined(SPOTLIGHT1) || defined(DIRLIGHT1)
  48. uniform mat4 lightMatrix1;
  49. varying vec4 vPositionFromLight1;
  50. #endif
  51. #if defined(SPOTLIGHT2) || defined(DIRLIGHT2)
  52. uniform mat4 lightMatrix2;
  53. varying vec4 vPositionFromLight2;
  54. #endif
  55. #if defined(SPOTLIGHT3) || defined(DIRLIGHT3)
  56. uniform mat4 lightMatrix3;
  57. varying vec4 vPositionFromLight3;
  58. #endif
  59. #endif
  60. void main(void) {
  61. #include<instancesVertex>
  62. #include<bonesVertex>
  63. gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
  64. vec4 worldPos = finalWorld * vec4(position, 1.0);
  65. vPositionW = vec3(worldPos);
  66. #ifdef NORMAL
  67. vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
  68. #endif
  69. // Texture coordinates
  70. #ifndef UV1
  71. vec2 uv = vec2(0., 0.);
  72. #endif
  73. #ifndef UV2
  74. vec2 uv2 = vec2(0., 0.);
  75. #endif
  76. #ifdef DIFFUSE
  77. if (vDiffuseInfos.x == 0.)
  78. {
  79. vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
  80. }
  81. else
  82. {
  83. vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
  84. }
  85. #endif
  86. // Clip plane
  87. #ifdef CLIPPLANE
  88. fClipDistance = dot(worldPos, vClipPlane);
  89. #endif
  90. // Fog
  91. #include<fogVertex>
  92. // Shadows
  93. #ifdef SHADOWS
  94. #if defined(SPOTLIGHT0) || defined(DIRLIGHT0)
  95. vPositionFromLight0 = lightMatrix0 * worldPos;
  96. #endif
  97. #if defined(SPOTLIGHT1) || defined(DIRLIGHT1)
  98. vPositionFromLight1 = lightMatrix1 * worldPos;
  99. #endif
  100. #if defined(SPOTLIGHT2) || defined(DIRLIGHT2)
  101. vPositionFromLight2 = lightMatrix2 * worldPos;
  102. #endif
  103. #if defined(SPOTLIGHT3) || defined(DIRLIGHT3)
  104. vPositionFromLight3 = lightMatrix3 * worldPos;
  105. #endif
  106. #endif
  107. // Vertex color
  108. #ifdef VERTEXCOLOR
  109. vColor = color;
  110. #endif
  111. // Point size
  112. #ifdef POINTSIZE
  113. gl_PointSize = pointSize;
  114. #endif
  115. }