gradient.fragment.fx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #ifdef VERTEXCOLOR
  51. baseColor.rgb *= vColor.rgb;
  52. #endif
  53. // Bump
  54. #ifdef NORMAL
  55. vec3 normalW = normalize(vNormalW);
  56. #else
  57. vec3 normalW = vec3(1.0, 1.0, 1.0);
  58. #endif
  59. // Lighting
  60. vec3 diffuseBase = vec3(0., 0., 0.);
  61. lightingInfo info;
  62. float shadow = 1.;
  63. float glossiness = 0.;
  64. #include<lightFragment>[0]
  65. #include<lightFragment>[1]
  66. #include<lightFragment>[2]
  67. #include<lightFragment>[3]
  68. #ifdef VERTEXALPHA
  69. alpha *= vColor.a;
  70. #endif
  71. vec3 finalDiffuse = clamp(diffuseBase * diffuseColor, 0.0, 1.0) * baseColor.rgb;
  72. // Composition
  73. vec4 color = vec4(finalDiffuse, alpha);
  74. #include<fogFragment>
  75. gl_FragColor = color;
  76. }