Debian Codegraph @

screensaver.shadertoy/resources/shaders/worleynoisewaters.frag.glsl

raw
1 // Taken from https://www.shadertoy.com/view/llS3RK
2
3 /*by mu6k, Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.*/
4
5 //Calculate the squared length of a vector
6 float length2(vec2 p){
7 return dot(p,p);
8 }
9
10 //Generate some noise to scatter points.
11 float noise(vec2 p){
12 return fract(sin(fract(sin(p.x) * (43.13311)) + p.y) * 31.0011);
13 }
14
15 float worley(vec2 p) {
16 //Set our distance to infinity
17 float d = 1e30;
18 //For the 9 surrounding grid points
19 for (int xo = -1; xo <= 1; ++xo) {
20 for (int yo = -1; yo <= 1; ++yo) {
21 //Floor our vec2 and add an offset to create our point
22 vec2 tp = floor(p) + vec2(xo, yo);
23 //Calculate the minimum distance for this grid point
24 //Mix in the noise value too!
25 d = min(d, length2(p - tp - noise(tp)));
26 }
27 }
28 return 3.0*exp(-4.0*abs(2.5*d - 1.0));
29 }
30
31 float fworley(vec2 p) {
32 //Stack noise layers
33 return sqrt(sqrt(sqrt(
34 worley(p*5.0 + 0.05*iTime) *
35 sqrt(worley(p * 50.0 + 0.12 + -0.1*iTime)) *
36 sqrt(sqrt(worley(p * -10.0 + 0.03*iTime))))));
37 }
38
39 void mainImage( out vec4 fragColor, in vec2 fragCoord )
40 {
41 vec2 uv = fragCoord.xy / iResolution.xy;
42 //Calculate an intensity
43 float t = fworley(uv * iResolution.xy / 1500.0);
44 //Add some gradient
45 t*=exp(-length2(abs(0.7*uv - 1.0)));
46 //Make it blue!
47 fragColor = vec4(t * vec3(0.1, 1.1*t, pow(t, 0.5-t)), 1.0);
48 }
49