gradient.fragment.fx 1.9 KB

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