fire.vertex.fx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. // Uniforms
  17. #ifdef INSTANCES
  18. attribute vec4 world0;
  19. attribute vec4 world1;
  20. attribute vec4 world2;
  21. attribute vec4 world3;
  22. #else
  23. uniform mat4 world;
  24. #endif
  25. uniform mat4 view;
  26. uniform mat4 viewProjection;
  27. #ifdef DIFFUSE
  28. varying vec2 vDiffuseUV;
  29. #endif
  30. #if NUM_BONE_INFLUENCERS > 0
  31. uniform mat4 mBones[BonesPerMesh];
  32. attribute vec4 matricesIndices;
  33. attribute vec4 matricesWeights;
  34. #if NUM_BONE_INFLUENCERS > 4
  35. attribute vec4 matricesIndicesExtra;
  36. attribute vec4 matricesWeightsExtra;
  37. #endif
  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. // Fire
  58. uniform float time;
  59. uniform float speed;
  60. varying vec2 vDistortionCoords1;
  61. varying vec2 vDistortionCoords2;
  62. varying vec2 vDistortionCoords3;
  63. void main(void) {
  64. mat4 finalWorld;
  65. #ifdef INSTANCES
  66. finalWorld = mat4(world0, world1, world2, world3);
  67. #else
  68. finalWorld = world;
  69. #endif
  70. #if NUM_BONE_INFLUENCERS > 0
  71. mat4 influence;
  72. influence = mBones[int(matricesIndices[0])] * matricesWeights[0];
  73. #if NUM_BONE_INFLUENCERS > 1
  74. influence += mBones[int(matricesIndices[1])] * matricesWeights[1];
  75. #endif
  76. #if NUM_BONE_INFLUENCERS > 2
  77. influence += mBones[int(matricesIndices[2])] * matricesWeights[2];
  78. #endif
  79. #if NUM_BONE_INFLUENCERS > 3
  80. influence += mBones[int(matricesIndices[3])] * matricesWeights[3];
  81. #endif
  82. #if NUM_BONE_INFLUENCERS > 4
  83. influence += mBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];
  84. #endif
  85. #if NUM_BONE_INFLUENCERS > 5
  86. influence += mBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];
  87. #endif
  88. #if NUM_BONE_INFLUENCERS > 6
  89. influence += mBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];
  90. #endif
  91. #if NUM_BONE_INFLUENCERS > 7
  92. influence += mBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];
  93. #endif
  94. finalWorld = finalWorld * influence;
  95. #endif
  96. gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
  97. vec4 worldPos = finalWorld * vec4(position, 1.0);
  98. vPositionW = vec3(worldPos);
  99. #ifdef NORMAL
  100. vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
  101. #endif
  102. // Texture coordinates
  103. #ifdef DIFFUSE
  104. vDiffuseUV = uv;
  105. vDiffuseUV.y -= 0.2;
  106. #endif
  107. // Clip plane
  108. #ifdef CLIPPLANE
  109. fClipDistance = dot(worldPos, vClipPlane);
  110. #endif
  111. // Fog
  112. #ifdef FOG
  113. fFogDistance = (view * worldPos).z;
  114. #endif
  115. // Vertex color
  116. #ifdef VERTEXCOLOR
  117. vColor = color;
  118. #endif
  119. // Point size
  120. #ifdef POINTSIZE
  121. gl_PointSize = pointSize;
  122. #endif
  123. // Fire
  124. vec3 layerSpeed = vec3(-0.2, -0.52, -0.1) * speed;
  125. vDistortionCoords1.x = uv.x;
  126. vDistortionCoords1.y = uv.y + layerSpeed.x * time / 1000.0;
  127. vDistortionCoords2.x = uv.x;
  128. vDistortionCoords2.y = uv.y + layerSpeed.y * time / 1000.0;
  129. vDistortionCoords3.x = uv.x;
  130. vDistortionCoords3.y = uv.y + layerSpeed.z * time / 1000.0;
  131. }