gradient.fragment.fx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. precision highp float;
  2. // Constants
  3. uniform vec3 vEyePosition;
  4. uniform vec4 vDiffuseColor;
  5. // Gradient variables
  6. uniform vec4 topColor;
  7. uniform vec4 bottomColor;
  8. uniform float offset;
  9. uniform float smoothness;
  10. // Input
  11. varying vec3 vPositionW;
  12. #ifdef NORMAL
  13. varying vec3 vNormalW;
  14. #endif
  15. #ifdef VERTEXCOLOR
  16. varying vec4 vColor;
  17. #endif
  18. // Helper functions
  19. #include<helperFunctions>
  20. // Lights
  21. #include<__decl__lightFragment>[0]
  22. #include<__decl__lightFragment>[1]
  23. #include<__decl__lightFragment>[2]
  24. #include<__decl__lightFragment>[3]
  25. #include<lightsFragmentFunctions>
  26. #include<shadowsFragmentFunctions>
  27. // Samplers
  28. #ifdef DIFFUSE
  29. varying vec2 vDiffuseUV;
  30. uniform sampler2D diffuseSampler;
  31. uniform vec2 vDiffuseInfos;
  32. #endif
  33. #include<clipPlaneFragmentDeclaration>
  34. // Fog
  35. #include<fogFragmentDeclaration>
  36. void main(void) {
  37. #include<clipPlaneFragment>
  38. vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
  39. float h = normalize(vPositionW).y + offset;
  40. float mysmoothness = clamp(smoothness, 0.01, max(smoothness, 10.));
  41. vec4 baseColor = mix(bottomColor, topColor, max(pow(max(h, 0.0), mysmoothness), 0.0));
  42. // Base color
  43. vec3 diffuseColor = baseColor.rgb;
  44. // Alpha
  45. float alpha = baseColor.a;
  46. #ifdef ALPHATEST
  47. if (baseColor.a < 0.4)
  48. discard;
  49. #endif
  50. #include<depthPrePass>
  51. #ifdef VERTEXCOLOR
  52. baseColor.rgb *= vColor.rgb;
  53. #endif
  54. // Bump
  55. #ifdef NORMAL
  56. vec3 normalW = normalize(vNormalW);
  57. #else
  58. vec3 normalW = vec3(1.0, 1.0, 1.0);
  59. #endif
  60. // Lighting
  61. vec3 diffuseBase = vec3(0., 0., 0.);
  62. lightingInfo info;
  63. float shadow = 1.;
  64. float glossiness = 0.;
  65. #include<lightFragment>[0]
  66. #include<lightFragment>[1]
  67. #include<lightFragment>[2]
  68. #include<lightFragment>[3]
  69. #ifdef VERTEXALPHA
  70. alpha *= vColor.a;
  71. #endif
  72. vec3 finalDiffuse = clamp(diffuseBase * diffuseColor, 0.0, 1.0) * baseColor.rgb;
  73. // Composition
  74. vec4 color = vec4(finalDiffuse, alpha);
  75. #include<fogFragment>
  76. gl_FragColor = color;
  77. }