legacypbr.vertex.fx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. precision mediump float;
  2. // Attributes
  3. attribute vec3 position;
  4. attribute vec3 normal;
  5. #ifdef UV1
  6. attribute vec2 uv;
  7. #endif
  8. #ifdef UV2
  9. attribute vec2 uv2;
  10. #endif
  11. #ifdef VERTEXCOLOR
  12. attribute vec4 color;
  13. #endif
  14. #ifdef BONES
  15. attribute vec4 matricesIndices;
  16. attribute vec4 matricesWeights;
  17. #endif
  18. // Uniforms
  19. uniform mat4 world;
  20. uniform mat4 view;
  21. uniform mat4 viewProjection;
  22. #ifdef DIFFUSE
  23. varying vec2 vDiffuseUV;
  24. uniform mat4 diffuseMatrix;
  25. uniform vec2 vDiffuseInfos;
  26. #endif
  27. #ifdef AMBIENT
  28. varying vec2 vAmbientUV;
  29. uniform mat4 ambientMatrix;
  30. uniform vec2 vAmbientInfos;
  31. #endif
  32. #ifdef OPACITY
  33. varying vec2 vOpacityUV;
  34. uniform mat4 opacityMatrix;
  35. uniform vec2 vOpacityInfos;
  36. #endif
  37. #ifdef EMISSIVE
  38. varying vec2 vEmissiveUV;
  39. uniform vec2 vEmissiveInfos;
  40. uniform mat4 emissiveMatrix;
  41. #endif
  42. #if defined(SPECULAR) && defined(SPECULARTERM)
  43. varying vec2 vSpecularUV;
  44. uniform vec2 vSpecularInfos;
  45. uniform mat4 specularMatrix;
  46. #endif
  47. #ifdef BONES
  48. uniform mat4 mBones[BonesPerMesh];
  49. #endif
  50. // Output
  51. varying vec3 vPositionW;
  52. varying vec3 vNormalW;
  53. #ifdef VERTEXCOLOR
  54. varying vec4 vColor;
  55. #endif
  56. #ifdef CLIPPLANE
  57. uniform vec4 vClipPlane;
  58. varying float fClipDistance;
  59. #endif
  60. void main(void) {
  61. mat4 finalWorld;
  62. #ifdef BONES
  63. mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;
  64. mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;
  65. mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;
  66. #ifdef BONES4
  67. mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;
  68. finalWorld = world * (m0 + m1 + m2 + m3);
  69. #else
  70. finalWorld = world * (m0 + m1 + m2);
  71. #endif
  72. #else
  73. finalWorld = world;
  74. #endif
  75. gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
  76. vec4 worldPos = finalWorld * vec4(position, 1.0);
  77. vPositionW = vec3(worldPos);
  78. vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
  79. // Texture coordinates
  80. #ifndef UV1
  81. vec2 uv = vec2(0., 0.);
  82. #endif
  83. #ifndef UV2
  84. vec2 uv2 = vec2(0., 0.);
  85. #endif
  86. #ifdef DIFFUSE
  87. if (vDiffuseInfos.x == 0.)
  88. {
  89. vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
  90. }
  91. else
  92. {
  93. vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
  94. }
  95. #endif
  96. #ifdef AMBIENT
  97. if (vAmbientInfos.x == 0.)
  98. {
  99. vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));
  100. }
  101. else
  102. {
  103. vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));
  104. }
  105. #endif
  106. #ifdef OPACITY
  107. if (vOpacityInfos.x == 0.)
  108. {
  109. vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));
  110. }
  111. else
  112. {
  113. vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));
  114. }
  115. #endif
  116. #ifdef EMISSIVE
  117. if (vEmissiveInfos.x == 0.)
  118. {
  119. vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));
  120. }
  121. else
  122. {
  123. vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));
  124. }
  125. #endif
  126. #if defined(SPECULAR) && defined(SPECULARTERM)
  127. if (vSpecularInfos.x == 0.)
  128. {
  129. vSpecularUV = vec2(specularMatrix * vec4(uv, 1.0, 0.0));
  130. }
  131. else
  132. {
  133. vSpecularUV = vec2(specularMatrix * vec4(uv2, 1.0, 0.0));
  134. }
  135. #endif
  136. // Clip plane
  137. #ifdef CLIPPLANE
  138. fClipDistance = dot(worldPos, vClipPlane);
  139. #endif
  140. // Vertex color
  141. #ifdef VERTEXCOLOR
  142. vColor = color;
  143. #endif
  144. }