simple.vertex.fx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #ifdef FOG
  42. varying float fFogDistance;
  43. #endif
  44. #ifdef SHADOWS
  45. #if defined(SPOTLIGHT0) || defined(DIRLIGHT0)
  46. uniform mat4 lightMatrix0;
  47. varying vec4 vPositionFromLight0;
  48. #endif
  49. #if defined(SPOTLIGHT1) || defined(DIRLIGHT1)
  50. uniform mat4 lightMatrix1;
  51. varying vec4 vPositionFromLight1;
  52. #endif
  53. #if defined(SPOTLIGHT2) || defined(DIRLIGHT2)
  54. uniform mat4 lightMatrix2;
  55. varying vec4 vPositionFromLight2;
  56. #endif
  57. #if defined(SPOTLIGHT3) || defined(DIRLIGHT3)
  58. uniform mat4 lightMatrix3;
  59. varying vec4 vPositionFromLight3;
  60. #endif
  61. #endif
  62. void main(void) {
  63. #include<instancesVertex>
  64. #include<bonesVertex>
  65. gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
  66. vec4 worldPos = finalWorld * vec4(position, 1.0);
  67. vPositionW = vec3(worldPos);
  68. #ifdef NORMAL
  69. vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
  70. #endif
  71. // Texture coordinates
  72. #ifndef UV1
  73. vec2 uv = vec2(0., 0.);
  74. #endif
  75. #ifndef UV2
  76. vec2 uv2 = vec2(0., 0.);
  77. #endif
  78. #ifdef DIFFUSE
  79. if (vDiffuseInfos.x == 0.)
  80. {
  81. vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
  82. }
  83. else
  84. {
  85. vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
  86. }
  87. #endif
  88. // Clip plane
  89. #ifdef CLIPPLANE
  90. fClipDistance = dot(worldPos, vClipPlane);
  91. #endif
  92. // Fog
  93. #ifdef FOG
  94. fFogDistance = (view * worldPos).z;
  95. #endif
  96. // Shadows
  97. #ifdef SHADOWS
  98. #if defined(SPOTLIGHT0) || defined(DIRLIGHT0)
  99. vPositionFromLight0 = lightMatrix0 * worldPos;
  100. #endif
  101. #if defined(SPOTLIGHT1) || defined(DIRLIGHT1)
  102. vPositionFromLight1 = lightMatrix1 * worldPos;
  103. #endif
  104. #if defined(SPOTLIGHT2) || defined(DIRLIGHT2)
  105. vPositionFromLight2 = lightMatrix2 * worldPos;
  106. #endif
  107. #if defined(SPOTLIGHT3) || defined(DIRLIGHT3)
  108. vPositionFromLight3 = lightMatrix3 * worldPos;
  109. #endif
  110. #endif
  111. // Vertex color
  112. #ifdef VERTEXCOLOR
  113. vColor = color;
  114. #endif
  115. // Point size
  116. #ifdef POINTSIZE
  117. gl_PointSize = pointSize;
  118. #endif
  119. }