fire.vertex.fx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. #ifdef BONES
  17. attribute vec4 matricesIndices;
  18. attribute vec4 matricesWeights;
  19. #endif
  20. // Uniforms
  21. #ifdef INSTANCES
  22. attribute vec4 world0;
  23. attribute vec4 world1;
  24. attribute vec4 world2;
  25. attribute vec4 world3;
  26. #else
  27. uniform mat4 world;
  28. #endif
  29. uniform mat4 view;
  30. uniform mat4 viewProjection;
  31. #ifdef DIFFUSE
  32. varying vec2 vDiffuseUV;
  33. uniform mat4 diffuseMatrix;
  34. uniform vec2 vDiffuseInfos;
  35. #endif
  36. #ifdef BONES
  37. uniform mat4 mBones[BonesPerMesh];
  38. #endif
  39. #ifdef POINTSIZE
  40. uniform float pointSize;
  41. #endif
  42. // Output
  43. varying vec3 vPositionW;
  44. #ifdef NORMAL
  45. varying vec3 vNormalW;
  46. #endif
  47. #ifdef VERTEXCOLOR
  48. varying vec4 vColor;
  49. #endif
  50. #ifdef CLIPPLANE
  51. uniform vec4 vClipPlane;
  52. varying float fClipDistance;
  53. #endif
  54. #ifdef FOG
  55. varying float fFogDistance;
  56. #endif
  57. #ifdef SHADOWS
  58. #ifdef LIGHT0
  59. uniform mat4 lightMatrix0;
  60. varying vec4 vPositionFromLight0;
  61. #endif
  62. #ifdef LIGHT1
  63. uniform mat4 lightMatrix1;
  64. varying vec4 vPositionFromLight1;
  65. #endif
  66. #ifdef LIGHT2
  67. uniform mat4 lightMatrix2;
  68. varying vec4 vPositionFromLight2;
  69. #endif
  70. #ifdef LIGHT3
  71. uniform mat4 lightMatrix3;
  72. varying vec4 vPositionFromLight3;
  73. #endif
  74. #endif
  75. // Fire
  76. uniform float time;
  77. varying vec2 vDistortionCoords1;
  78. varying vec2 vDistortionCoords2;
  79. varying vec2 vDistortionCoords3;
  80. void main(void) {
  81. mat4 finalWorld;
  82. #ifdef INSTANCES
  83. finalWorld = mat4(world0, world1, world2, world3);
  84. #else
  85. finalWorld = world;
  86. #endif
  87. #ifdef BONES
  88. mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;
  89. mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;
  90. mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;
  91. #ifdef BONES4
  92. mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;
  93. finalWorld = finalWorld * (m0 + m1 + m2 + m3);
  94. #else
  95. finalWorld = finalWorld * (m0 + m1 + m2);
  96. #endif
  97. #endif
  98. gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
  99. vec4 worldPos = finalWorld * vec4(position, 1.0);
  100. vPositionW = vec3(worldPos);
  101. #ifdef NORMAL
  102. vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
  103. #endif
  104. // Texture coordinates
  105. #ifndef UV1
  106. vec2 uv = vec2(0., 0.);
  107. #endif
  108. #ifndef UV2
  109. vec2 uv2 = vec2(0., 0.);
  110. #endif
  111. #ifdef DIFFUSE
  112. if (vDiffuseInfos.x == 0.)
  113. {
  114. vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
  115. }
  116. else
  117. {
  118. vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
  119. }
  120. #endif
  121. // Clip plane
  122. #ifdef CLIPPLANE
  123. fClipDistance = dot(worldPos, vClipPlane);
  124. #endif
  125. // Fog
  126. #ifdef FOG
  127. fFogDistance = (view * worldPos).z;
  128. #endif
  129. // Shadows
  130. #ifdef SHADOWS
  131. #ifdef LIGHT0
  132. vPositionFromLight0 = lightMatrix0 * worldPos;
  133. #endif
  134. #ifdef LIGHT1
  135. vPositionFromLight1 = lightMatrix1 * worldPos;
  136. #endif
  137. #ifdef LIGHT2
  138. vPositionFromLight2 = lightMatrix2 * worldPos;
  139. #endif
  140. #ifdef LIGHT3
  141. vPositionFromLight3 = lightMatrix3 * worldPos;
  142. #endif
  143. #endif
  144. // Vertex color
  145. #ifdef VERTEXCOLOR
  146. vColor = color;
  147. #endif
  148. // Point size
  149. #ifdef POINTSIZE
  150. gl_PointSize = pointSize;
  151. #endif
  152. // Fire
  153. vec3 layerSpeed = vec3(0.2, 0.52, 0.1);
  154. vDistortionCoords1.x = uv.x;
  155. vDistortionCoords1.y = uv.y + layerSpeed.x * time / 1000.0;
  156. vDistortionCoords2.x = uv.x;
  157. vDistortionCoords2.y = uv.y + layerSpeed.y * time / 1000.0;
  158. vDistortionCoords3.x = uv.x;
  159. vDistortionCoords3.y = uv.y + layerSpeed.z * time / 1000.0;
  160. }