#version 300 es /* https://gpfault.net/posts/perlin-noise.txt.html */ precision highp float; // Uniform variables uniform float u_time; // Output variable out vec4 fragColor; // Hash function to generate pseudo-random values float hash(vec3 p) { p = fract(p * vec3(443.8975, 397.2973, 491.1871)); p += dot(p.zxy, p.yxz + 19.19); return fract(p.x * p.y * p.z); } vec3 grad(vec3 p) { // Generate random vector using hash function vec3 rand = vec3( hash(p), hash(p + 1234.5678), hash(p + 8765.4321) ); return normalize(rand * 2.0 - vec3(1.0)); } float fade(float t) { return t*t*t*(t*(t*6.0 - 15.0) + 10.0); } float noise(vec3 p) { vec3 p0 = floor(p); vec3 p1 = p0 + vec3(1.0, 0.0, 0.0); vec3 p2 = p0 + vec3(0.0, 1.0, 0.0); vec3 p3 = p0 + vec3(1.0, 1.0, 0.0); vec3 p4 = p0 + vec3(0.0, 0.0, 1.0); vec3 p5 = p4 + vec3(1.0, 0.0, 0.0); vec3 p6 = p4 + vec3(0.0, 1.0, 0.0); vec3 p7 = p4 + vec3(1.0, 1.0, 0.0); vec3 g0 = grad(p0); vec3 g1 = grad(p1); vec3 g2 = grad(p2); vec3 g3 = grad(p3); vec3 g4 = grad(p4); vec3 g5 = grad(p5); vec3 g6 = grad(p6); vec3 g7 = grad(p7); float t0 = p.x - p0.x; float fade_t0 = fade(t0); float t1 = p.y - p0.y; float fade_t1 = fade(t1); float t2 = p.z - p0.z; float fade_t2 = fade(t2); float p0p1 = (1.0 - fade_t0) * dot(g0, (p - p0)) + fade_t0 * dot(g1, (p - p1)); float p2p3 = (1.0 - fade_t0) * dot(g2, (p - p2)) + fade_t0 * dot(g3, (p - p3)); float p4p5 = (1.0 - fade_t0) * dot(g4, (p - p4)) + fade_t0 * dot(g5, (p - p5)); float p6p7 = (1.0 - fade_t0) * dot(g6, (p - p6)) + fade_t0 * dot(g7, (p - p7)); float y1 = (1.0 - fade_t1) * p0p1 + fade_t1 * p2p3; float y2 = (1.0 - fade_t1) * p4p5 + fade_t1 * p6p7; return (1.0 - fade_t2) * y1 + fade_t2 * y2; } void main() { float utm = u_time * 5.0; float n = noise(vec3(gl_FragCoord.xy, utm)/128.0)/ 1.0 + noise(vec3(gl_FragCoord.xy, utm)/64.0) / 2.0 + noise(vec3(gl_FragCoord.xy, utm)/32.0) / 16.0; // noise(vec3(gl_FragCoord.xy, utm)/16.0) / 16.0; fragColor = vec4(vec3(n)+0.5, 1.0); }