cloudProceduralTexture.fragment.fx 680 B

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