fire.fragment.fx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. precision highp float;
  2. // Constants
  3. uniform vec3 vEyePosition;
  4. // Input
  5. varying vec3 vPositionW;
  6. #ifdef VERTEXCOLOR
  7. varying vec4 vColor;
  8. #endif
  9. // Samplers
  10. #ifdef DIFFUSE
  11. varying vec2 vDiffuseUV;
  12. uniform sampler2D diffuseSampler;
  13. uniform vec2 vDiffuseInfos;
  14. #endif
  15. // Fire
  16. uniform sampler2D distortionSampler;
  17. uniform sampler2D opacitySampler;
  18. varying vec2 vDistortionCoords1;
  19. varying vec2 vDistortionCoords2;
  20. varying vec2 vDistortionCoords3;
  21. #include<clipPlaneFragmentDeclaration>
  22. // Fog
  23. #include<fogFragmentDeclaration>
  24. vec4 bx2(vec4 x)
  25. {
  26. return vec4(2.0) * x - vec4(1.0);
  27. }
  28. void main(void) {
  29. // Clip plane
  30. #include<clipPlaneFragment>
  31. vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
  32. // Base color
  33. vec4 baseColor = vec4(1., 1., 1., 1.);
  34. // Alpha
  35. float alpha = 1.0;
  36. #ifdef DIFFUSE
  37. // Fire
  38. const float distortionAmount0 = 0.092;
  39. const float distortionAmount1 = 0.092;
  40. const float distortionAmount2 = 0.092;
  41. vec2 heightAttenuation = vec2(0.3, 0.39);
  42. vec4 noise0 = texture2D(distortionSampler, vDistortionCoords1);
  43. vec4 noise1 = texture2D(distortionSampler, vDistortionCoords2);
  44. vec4 noise2 = texture2D(distortionSampler, vDistortionCoords3);
  45. vec4 noiseSum = bx2(noise0) * distortionAmount0 + bx2(noise1) * distortionAmount1 + bx2(noise2) * distortionAmount2;
  46. vec4 perturbedBaseCoords = vec4(vDiffuseUV, 0.0, 1.0) + noiseSum * (vDiffuseUV.y * heightAttenuation.x + heightAttenuation.y);
  47. vec4 opacityColor = texture2D(opacitySampler, perturbedBaseCoords.xy);
  48. #ifdef ALPHATEST
  49. if (opacityColor.r < 0.1)
  50. discard;
  51. #endif
  52. baseColor = texture2D(diffuseSampler, perturbedBaseCoords.xy) * 2.0;
  53. baseColor *= opacityColor;
  54. baseColor.rgb *= vDiffuseInfos.y;
  55. #endif
  56. #ifdef VERTEXCOLOR
  57. baseColor.rgb *= vColor.rgb;
  58. #endif
  59. // Lighting
  60. vec3 diffuseBase = vec3(1.0, 1.0, 1.0);
  61. #ifdef VERTEXALPHA
  62. alpha *= vColor.a;
  63. #endif
  64. // Composition
  65. vec4 color = vec4(baseColor.rgb, alpha);
  66. #include<fogFragment>
  67. gl_FragColor = color;
  68. }