roadProceduralTexture.fragment.fx 719 B

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