triplanar.vertex.fx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. precision highp float;
  2. // Attributes
  3. attribute vec3 position;
  4. #ifdef NORMAL
  5. attribute vec3 normal;
  6. #endif
  7. #ifdef VERTEXCOLOR
  8. attribute vec4 color;
  9. #endif
  10. #include<bonesDeclaration>
  11. // Uniforms
  12. #include<instancesDeclaration>
  13. uniform mat4 view;
  14. uniform mat4 viewProjection;
  15. #ifdef DIFFUSEX
  16. varying vec2 vTextureUVX;
  17. #endif
  18. #ifdef DIFFUSEY
  19. varying vec2 vTextureUVY;
  20. #endif
  21. #ifdef DIFFUSEZ
  22. varying vec2 vTextureUVZ;
  23. #endif
  24. uniform float tileSize;
  25. #ifdef POINTSIZE
  26. uniform float pointSize;
  27. #endif
  28. // Output
  29. varying vec3 vPositionW;
  30. #ifdef NORMAL
  31. varying mat3 tangentSpace;
  32. #endif
  33. #ifdef VERTEXCOLOR
  34. varying vec4 vColor;
  35. #endif
  36. #include<clipPlaneVertexDeclaration>
  37. #include<fogVertexDeclaration>
  38. #include<__decl__lightFragment>[0..maxSimultaneousLights]
  39. void main(void)
  40. {
  41. #include<instancesVertex>
  42. #include<bonesVertex>
  43. vec4 worldPos = finalWorld * vec4(position, 1.0);
  44. gl_Position = viewProjection * worldPos;
  45. vPositionW = vec3(worldPos);
  46. #ifdef DIFFUSEX
  47. vTextureUVX = worldPos.zy / tileSize;
  48. #endif
  49. #ifdef DIFFUSEY
  50. vTextureUVY = worldPos.xz / tileSize;
  51. #endif
  52. #ifdef DIFFUSEZ
  53. vTextureUVZ = worldPos.xy / tileSize;
  54. #endif
  55. #ifdef NORMAL
  56. // Compute tangent space (used for normal mapping + tri planar color mapping)
  57. vec3 xtan = vec3(0,0,1);//tangent space for the X aligned plane
  58. vec3 xbin = vec3(0,1,0);
  59. vec3 ytan = vec3(1,0,0);//tangent space for the Y aligned plane
  60. vec3 ybin = vec3(0,0,1);
  61. vec3 ztan = vec3(1,0,0);//tangent space for the Z aligned plane
  62. vec3 zbin = vec3(0,1,0);
  63. vec3 normalizedNormal = normalize(normal);
  64. normalizedNormal *= normalizedNormal;
  65. vec3 worldBinormal = normalize(xbin * normalizedNormal.x + ybin * normalizedNormal.y + zbin * normalizedNormal.z);
  66. vec3 worldTangent = normalize(xtan * normalizedNormal.x + ytan * normalizedNormal.y + ztan * normalizedNormal.z);
  67. worldTangent = (world * vec4(worldTangent, 1.0)).xyz;
  68. worldBinormal = (world * vec4(worldBinormal, 1.0)).xyz;
  69. vec3 worldNormal = normalize(cross(worldTangent, worldBinormal));
  70. tangentSpace[0] = worldTangent;
  71. tangentSpace[1] = worldBinormal;
  72. tangentSpace[2] = worldNormal;
  73. #endif
  74. // Clip plane
  75. #include<clipPlaneVertex>
  76. // Fog
  77. #include<fogVertex>
  78. // Shadows
  79. #include<shadowsVertex>[0..maxSimultaneousLights]
  80. // Vertex color
  81. #ifdef VERTEXCOLOR
  82. vColor = color;
  83. #endif
  84. // Point size
  85. #ifdef POINTSIZE
  86. gl_PointSize = pointSize;
  87. #endif
  88. }