fire.vertex.fx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. #endif
  34. #ifdef BONES
  35. uniform mat4 mBones[BonesPerMesh];
  36. #endif
  37. #ifdef POINTSIZE
  38. uniform float pointSize;
  39. #endif
  40. // Output
  41. varying vec3 vPositionW;
  42. #ifdef NORMAL
  43. varying vec3 vNormalW;
  44. #endif
  45. #ifdef VERTEXCOLOR
  46. varying vec4 vColor;
  47. #endif
  48. #ifdef CLIPPLANE
  49. uniform vec4 vClipPlane;
  50. varying float fClipDistance;
  51. #endif
  52. #ifdef FOG
  53. varying float fFogDistance;
  54. #endif
  55. // Fire
  56. uniform float time;
  57. uniform float speed;
  58. varying vec2 vDistortionCoords1;
  59. varying vec2 vDistortionCoords2;
  60. varying vec2 vDistortionCoords3;
  61. void main(void) {
  62. mat4 finalWorld;
  63. #ifdef INSTANCES
  64. finalWorld = mat4(world0, world1, world2, world3);
  65. #else
  66. finalWorld = world;
  67. #endif
  68. #ifdef BONES
  69. mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;
  70. mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;
  71. mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;
  72. #ifdef BONES4
  73. mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;
  74. finalWorld = finalWorld * (m0 + m1 + m2 + m3);
  75. #else
  76. finalWorld = finalWorld * (m0 + m1 + m2);
  77. #endif
  78. #endif
  79. gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
  80. vec4 worldPos = finalWorld * vec4(position, 1.0);
  81. vPositionW = vec3(worldPos);
  82. #ifdef NORMAL
  83. vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
  84. #endif
  85. // Texture coordinates
  86. #ifdef DIFFUSE
  87. vDiffuseUV = uv;
  88. vDiffuseUV.y -= 0.2;
  89. #endif
  90. // Clip plane
  91. #ifdef CLIPPLANE
  92. fClipDistance = dot(worldPos, vClipPlane);
  93. #endif
  94. // Fog
  95. #ifdef FOG
  96. fFogDistance = (view * worldPos).z;
  97. #endif
  98. // Vertex color
  99. #ifdef VERTEXCOLOR
  100. vColor = color;
  101. #endif
  102. // Point size
  103. #ifdef POINTSIZE
  104. gl_PointSize = pointSize;
  105. #endif
  106. // Fire
  107. vec3 layerSpeed = vec3(-0.2, -0.52, -0.1) * speed;
  108. vDistortionCoords1.x = uv.x;
  109. vDistortionCoords1.y = uv.y + layerSpeed.x * time / 1000.0;
  110. vDistortionCoords2.x = uv.x;
  111. vDistortionCoords2.y = uv.y + layerSpeed.y * time / 1000.0;
  112. vDistortionCoords3.x = uv.x;
  113. vDistortionCoords3.y = uv.y + layerSpeed.z * time / 1000.0;
  114. }