Debian Codegraph @

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

raw
1 // Taken from https://www.shadertoy.com/view/lslXRS
2
3 //Noise animation - Lava
4 //by nimitz (twitter: @stormoid)
5
6
7 //Somewhat inspired by the concepts behind "flow noise"
8 //every octave of noise is modulated separately
9 //with displacement using a rotated vector field
10
11 //This is a more standard use of the flow noise
12 //unlike my normalized vector field version (https://www.shadertoy.com/view/MdlXRS)
13 //the noise octaves are actually displaced to create a directional flow
14
15 //Sinus ridged fbm is used for better effect.
16
17 #define time iTime*0.1
18
19 float hash21(in vec2 n){ return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453); }
20 mat2 makem2(in float theta){float c = cos(theta);float s = sin(theta);return mat2(c,-s,s,c);}
21 float noise( in vec2 x ){return texture(iChannel0, x*.01).x;}
22
23 vec2 gradn(vec2 p)
24 {
25 float ep = .09;
26 float gradx = noise(vec2(p.x+ep,p.y))-noise(vec2(p.x-ep,p.y));
27 float grady = noise(vec2(p.x,p.y+ep))-noise(vec2(p.x,p.y-ep));
28 return vec2(gradx,grady);
29 }
30
31 float flow(in vec2 p)
32 {
33 float z=2.;
34 float rz = 0.;
35 vec2 bp = p;
36 for (float i= 1.;i < 7.;i++ )
37 {
38 //primary flow speed
39 p += time*.6;
40
41 //secondary flow speed (speed of the perceived flow)
42 bp += time*1.9;
43
44 //displacement field (try changing time multiplier)
45 vec2 gr = gradn(i*p*.34+time*1.);
46
47 //rotation of the displacement field
48 gr*=makem2(time*6.-(0.05*p.x+0.03*p.y)*40.);
49
50 //displace the system
51 p += gr*.5;
52
53 //add noise octave
54 rz+= (sin(noise(p)*7.)*0.5+0.5)/z;
55
56 //blend factor (blending displaced system with base system)
57 //you could call this advection factor (.5 being low, .95 being high)
58 p = mix(bp,p,.77);
59
60 //intensity scaling
61 z *= 1.4;
62 //octave scaling
63 p *= 2.;
64 bp *= 1.9;
65 }
66 return rz;
67 }
68
69 void mainImage( out vec4 fragColor, in vec2 fragCoord )
70 {
71 vec2 p = fragCoord.xy / iResolution.xy-0.5;
72 p.x *= iResolution.x/iResolution.y;
73 p*= 3.;
74 float rz = flow(p);
75
76 vec3 col = vec3(.2,0.07,0.01)/rz;
77 col=pow(col,vec3(1.4));
78 fragColor = vec4(col,1.0);
79 }