fire.fragment.fx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. baseColor = texture2D(diffuseSampler, perturbedBaseCoords.xy) * 2.0;
  55. baseColor *= opacityColor;
  56. baseColor.rgb *= vDiffuseInfos.y;
  57. #endif
  58. #ifdef VERTEXCOLOR
  59. baseColor.rgb *= vColor.rgb;
  60. #endif
  61. // Lighting
  62. vec3 diffuseBase = vec3(1.0, 1.0, 1.0);
  63. #ifdef VERTEXALPHA
  64. alpha *= vColor.a;
  65. #endif
  66. // Composition
  67. vec4 color = vec4(baseColor.rgb, alpha);
  68. #include<fogFragment>
  69. gl_FragColor = color;
  70. }