lava.fragment.fx 3.0 KB

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