lava.fragment.fx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. precision highp float;
  2. // Constants
  3. uniform vec3 vEyePosition;
  4. uniform vec4 vDiffuseColor;
  5. // Input
  6. varying vec3 vPositionW;
  7. // MAGMAAAA
  8. uniform float time;
  9. uniform float speed;
  10. uniform float movingSpeed;
  11. uniform vec3 fogColor;
  12. uniform sampler2D noiseTexture;
  13. uniform float fogDensity;
  14. // Varying
  15. varying float noise;
  16. #ifdef NORMAL
  17. varying vec3 vNormalW;
  18. #endif
  19. #ifdef VERTEXCOLOR
  20. varying vec4 vColor;
  21. #endif
  22. // Lights
  23. #include<lightFragmentDeclaration>[0]
  24. #include<lightFragmentDeclaration>[1]
  25. #include<lightFragmentDeclaration>[2]
  26. #include<lightFragmentDeclaration>[3]
  27. #include<lightsFragmentFunctions>
  28. #include<shadowsFragmentFunctions>
  29. // Samplers
  30. #ifdef DIFFUSE
  31. varying vec2 vDiffuseUV;
  32. uniform sampler2D diffuseSampler;
  33. uniform vec2 vDiffuseInfos;
  34. #endif
  35. #include<clipPlaneFragmentDeclaration>
  36. // Fog
  37. #include<fogFragmentDeclaration>
  38. float random( vec3 scale, float seed ){
  39. return fract( sin( dot( gl_FragCoord.xyz + seed, scale ) ) * 43758.5453 + seed ) ;
  40. }
  41. void main(void) {
  42. #include<clipPlaneFragment>
  43. vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
  44. // Base color
  45. vec4 baseColor = vec4(1., 1., 1., 1.);
  46. vec3 diffuseColor = vDiffuseColor.rgb;
  47. // Alpha
  48. float alpha = vDiffuseColor.a;
  49. #ifdef DIFFUSE
  50. ////// MAGMA ///
  51. vec4 noiseTex = texture2D( noiseTexture, vDiffuseUV );
  52. vec2 T1 = vDiffuseUV + vec2( 1.5, -1.5 ) * time * 0.02;
  53. vec2 T2 = vDiffuseUV + vec2( -0.5, 2.0 ) * time * 0.01 * speed;
  54. T1.x += noiseTex.x * 2.0;
  55. T1.y += noiseTex.y * 2.0;
  56. T2.x -= noiseTex.y * 0.2 + time*0.001*movingSpeed;
  57. T2.y += noiseTex.z * 0.2 + time*0.002*movingSpeed;
  58. float p = texture2D( noiseTexture, T1 * 3.0 ).a;
  59. vec4 lavaColor = texture2D( diffuseSampler, T2 * 4.0);
  60. vec4 temp = lavaColor * ( vec4( p, p, p, p ) * 2. ) + ( lavaColor * lavaColor - 0.1 );
  61. baseColor = temp;
  62. float depth = gl_FragCoord.z * 4.0;
  63. const float LOG2 = 1.442695;
  64. float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );
  65. fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );
  66. baseColor = mix( baseColor, vec4( fogColor, baseColor.w ), fogFactor );
  67. diffuseColor = baseColor.rgb;
  68. ///// END MAGMA ////
  69. // baseColor = texture2D(diffuseSampler, vDiffuseUV);
  70. #ifdef ALPHATEST
  71. if (baseColor.a < 0.4)
  72. discard;
  73. #endif
  74. baseColor.rgb *= vDiffuseInfos.y;
  75. #endif
  76. #ifdef VERTEXCOLOR
  77. baseColor.rgb *= vColor.rgb;
  78. #endif
  79. // Bump
  80. #ifdef NORMAL
  81. vec3 normalW = normalize(vNormalW);
  82. #else
  83. vec3 normalW = vec3(1.0, 1.0, 1.0);
  84. #endif
  85. // Lighting
  86. vec3 diffuseBase = vec3(0., 0., 0.);
  87. lightingInfo info;
  88. float shadow = 1.;
  89. float glossiness = 0.;
  90. #include<lightFragment>[0]
  91. #include<lightFragment>[1]
  92. #include<lightFragment>[2]
  93. #include<lightFragment>[3]
  94. #ifdef VERTEXALPHA
  95. alpha *= vColor.a;
  96. #endif
  97. vec3 finalDiffuse = clamp(diffuseBase * diffuseColor, 0.0, 1.0) * baseColor.rgb;
  98. // Composition
  99. vec4 color = vec4(finalDiffuse, alpha);
  100. #include<fogFragment>
  101. gl_FragColor = color;
  102. }