fire.fragment.fx 2.0 KB

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