pbr.vertex.fx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 ALBEDO
  22. varying vec2 vAlbedoUV;
  23. uniform mat4 albedoMatrix;
  24. uniform vec2 vAlbedoInfos;
  25. #endif
  26. #ifdef AMBIENT
  27. varying vec2 vAmbientUV;
  28. uniform mat4 ambientMatrix;
  29. uniform vec2 vAmbientInfos;
  30. #endif
  31. #ifdef OPACITY
  32. varying vec2 vOpacityUV;
  33. uniform mat4 opacityMatrix;
  34. uniform vec2 vOpacityInfos;
  35. #endif
  36. #ifdef EMISSIVE
  37. varying vec2 vEmissiveUV;
  38. uniform vec2 vEmissiveInfos;
  39. uniform mat4 emissiveMatrix;
  40. #endif
  41. #ifdef LIGHTMAP
  42. varying vec2 vLightmapUV;
  43. uniform vec2 vLightmapInfos;
  44. uniform mat4 lightmapMatrix;
  45. #endif
  46. #if defined(REFLECTIVITY)
  47. varying vec2 vReflectivityUV;
  48. uniform vec2 vReflectivityInfos;
  49. uniform mat4 reflectivityMatrix;
  50. #endif
  51. #ifdef BUMP
  52. varying vec2 vBumpUV;
  53. uniform vec2 vBumpInfos;
  54. uniform mat4 bumpMatrix;
  55. #endif
  56. #ifdef POINTSIZE
  57. uniform float pointSize;
  58. #endif
  59. // Output
  60. varying vec3 vPositionW;
  61. #ifdef NORMAL
  62. varying vec3 vNormalW;
  63. #endif
  64. #ifdef VERTEXCOLOR
  65. varying vec4 vColor;
  66. #endif
  67. #include<clipPlaneVertexDeclaration>
  68. #include<fogVertexDeclaration>
  69. #include<shadowsVertexDeclaration>
  70. #ifdef REFLECTIONMAP_SKYBOX
  71. varying vec3 vPositionUVW;
  72. #endif
  73. #ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED
  74. varying vec3 vDirectionW;
  75. #endif
  76. #include<logDepthDeclaration>
  77. void main(void) {
  78. #ifdef REFLECTIONMAP_SKYBOX
  79. vPositionUVW = position;
  80. #endif
  81. #include<instancesVertex>
  82. #include<bonesVertex>
  83. gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
  84. vec4 worldPos = finalWorld * vec4(position, 1.0);
  85. vPositionW = vec3(worldPos);
  86. #ifdef NORMAL
  87. vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
  88. #endif
  89. #ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED
  90. vDirectionW = normalize(vec3(finalWorld * vec4(position, 0.0)));
  91. #endif
  92. // Texture coordinates
  93. #ifndef UV1
  94. vec2 uv = vec2(0., 0.);
  95. #endif
  96. #ifndef UV2
  97. vec2 uv2 = vec2(0., 0.);
  98. #endif
  99. #ifdef ALBEDO
  100. if (vAlbedoInfos.x == 0.)
  101. {
  102. vAlbedoUV = vec2(albedoMatrix * vec4(uv, 1.0, 0.0));
  103. }
  104. else
  105. {
  106. vAlbedoUV = vec2(albedoMatrix * vec4(uv2, 1.0, 0.0));
  107. }
  108. #endif
  109. #ifdef AMBIENT
  110. if (vAmbientInfos.x == 0.)
  111. {
  112. vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));
  113. }
  114. else
  115. {
  116. vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));
  117. }
  118. #endif
  119. #ifdef OPACITY
  120. if (vOpacityInfos.x == 0.)
  121. {
  122. vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));
  123. }
  124. else
  125. {
  126. vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));
  127. }
  128. #endif
  129. #ifdef EMISSIVE
  130. if (vEmissiveInfos.x == 0.)
  131. {
  132. vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));
  133. }
  134. else
  135. {
  136. vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));
  137. }
  138. #endif
  139. #ifdef LIGHTMAP
  140. if (vLightmapInfos.x == 0.)
  141. {
  142. vLightmapUV = vec2(lightmapMatrix * vec4(uv, 1.0, 0.0));
  143. }
  144. else
  145. {
  146. vLightmapUV = vec2(lightmapMatrix * vec4(uv2, 1.0, 0.0));
  147. }
  148. #endif
  149. #if defined(REFLECTIVITY)
  150. if (vReflectivityInfos.x == 0.)
  151. {
  152. vReflectivityUV = vec2(reflectivityMatrix * vec4(uv, 1.0, 0.0));
  153. }
  154. else
  155. {
  156. vReflectivityUV = vec2(reflectivityMatrix * vec4(uv2, 1.0, 0.0));
  157. }
  158. #endif
  159. #ifdef BUMP
  160. if (vBumpInfos.x == 0.)
  161. {
  162. vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));
  163. }
  164. else
  165. {
  166. vBumpUV = vec2(bumpMatrix * vec4(uv2, 1.0, 0.0));
  167. }
  168. #endif
  169. // Clip plane
  170. #include<clipPlaneVertex>
  171. // Fog
  172. #include<fogVertex>
  173. // Shadows
  174. #include<shadowsVertex>
  175. // Vertex color
  176. #ifdef VERTEXCOLOR
  177. vColor = color;
  178. #endif
  179. // Point size
  180. #ifdef POINTSIZE
  181. gl_PointSize = pointSize;
  182. #endif
  183. // Log. depth
  184. #include<logDepthVertex>
  185. }