cloud.fragment.fx 707 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifdef GL_ES
  2. precision highp float;
  3. #endif
  4. varying vec2 vUV;
  5. uniform vec3 skyColor;
  6. uniform vec3 cloudColor;
  7. float rand(vec2 n) {
  8. return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
  9. }
  10. float noise(vec2 n) {
  11. const vec2 d = vec2(0.0, 1.0);
  12. vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
  13. return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
  14. }
  15. float fbm(vec2 n) {
  16. float total = 0.0, amplitude = 1.0;
  17. for (int i = 0; i < 4; i++) {
  18. total += noise(n) * amplitude;
  19. n += n;
  20. amplitude *= 0.5;
  21. }
  22. return total;
  23. }
  24. void main() {
  25. vec2 p = vUV * 12.0;
  26. vec3 c = mix(skyColor, cloudColor, fbm(p));
  27. gl_FragColor = vec4(c, 1);
  28. }