WaterFragment.glsl 672 B

1234567891011121314151617181920212223242526
  1. // https://gamedevelopment.tutsplus.com/tutorials/a-beginners-guide-to-coding-graphics-shaders--cms-23313
  2. uniform vec3 waterColor;
  3. uniform vec3 bottomColor;
  4. uniform float wateroffset;
  5. uniform float waterexponent;
  6. varying vec3 vWorldPosition;
  7. void main() {
  8. float h = normalize( vWorldPosition * -1.0 + wateroffset ).y;
  9. gl_FragColor = vec4(
  10. // mix(x, y, a) performs a linear interpolation between x and y using a to weight between them.
  11. // The return value is computed as x×(1−a)+y×a.
  12. mix(
  13. waterColor,
  14. bottomColor,
  15. max(
  16. pow(
  17. max( h , 0.0),
  18. waterexponent
  19. ),
  20. 0.0
  21. )
  22. ),
  23. 1.0
  24. );
  25. }