Debian Codegraph @

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

raw
1 // Taken from https://www.shadertoy.com/view/Mts3zM
2
3 //Overly satisfying by nimitz (twitter: @stormoid)
4
5 //This might look like a lot of code but the base implementation of the gif itself is ~10loc
6
7 #define time iTime*1.2
8 #define pi 3.14159265
9
10 #define NUM 20.
11 #define PALETTE vec3(.0, 1.4, 2.)+1.5
12
13 #define COLORED
14 #define MIRROR
15 //#define ROTATE
16 #define ROT_OFST
17 #define TRIANGLE_NOISE
18
19 //#define SHOW_TRIANGLE_NOISE_ONLY
20
21 mat2 mm2(in float a){float c = cos(a), s = sin(a);return mat2(c,-s,s,c);}
22 float tri(in float x){return abs(fract(x)-.5);}
23 vec2 tri2(in vec2 p){return vec2(tri(p.x+tri(p.y*2.)),tri(p.y+tri(p.x*2.)));}
24 mat2 m2 = mat2( 0.970, 0.242, -0.242, 0.970 );
25
26 //Animated triangle noise, cheap and pretty decent looking.
27 float triangleNoise(in vec2 p)
28 {
29 float z=1.5;
30 float z2=1.5;
31 float rz = 0.;
32 vec2 bp = p;
33 for (float i=0.; i<=3.; i++ )
34 {
35 vec2 dg = tri2(bp*2.)*.8;
36 dg *= mm2(time*.3);
37 p += dg/z2;
38
39 bp *= 1.6;
40 z2 *= .6;
41 z *= 1.8;
42 p *= 1.2;
43 p*= m2;
44
45 rz+= (tri(p.x+tri(p.y)))/z;
46 }
47 return rz;
48 }
49
50 void mainImage( out vec4 fragColor, in vec2 fragCoord )
51 {
52 float aspect = iResolution.x/iResolution.y;
53 float w = 50./sqrt(iResolution.x*aspect+iResolution.y);
54
55 vec2 p = fragCoord.xy / iResolution.xy*2.-1.;
56 p.x *= aspect;
57 p*= 1.05;
58 vec2 bp = p;
59
60 #ifdef ROTATE
61 p *= mm2(time*.25);
62 #endif
63
64 float lp = length(p);
65 float id = floor(lp*NUM+.5)/NUM;
66
67 #ifdef ROT_OFST
68 p *= mm2(id*11.);
69 #endif
70
71 #ifdef MIRROR
72 p.y = abs(p.y);
73 #endif
74
75 //polar coords
76 vec2 plr = vec2(lp, atan(p.y, p.x));
77
78 //Draw concentric circles
79 float rz = 1.-pow(abs(sin(plr.x*pi*NUM))*1.25/pow(w,0.25),2.5);
80
81 //get the current arc length for a given id
82 float enp = plr.y+sin((time+id*5.5))*1.52-1.5;
83 rz *= smoothstep(0., 0.05, enp);
84
85 //smooth out both sides of the arcs (and clamp the number)
86 rz *= smoothstep(0.,.022*w/plr.x, enp)*step(id,1.);
87 #ifndef MIRROR
88 rz *= smoothstep(-0.01,.02*w/plr.x,pi-plr.y);
89 #endif
90
91 #ifdef TRIANGLE_NOISE
92 rz *= (triangleNoise(p/(w*w))*0.9+0.4);
93 vec3 col = (sin(PALETTE+id*5.+time)*0.5+0.5)*rz;
94 col += smoothstep(.4,1.,rz)*0.15;
95 col *= smoothstep(.2,1.,rz)+1.;
96
97 #else
98 vec3 col = (sin(PALETTE+id*5.+time)*0.5+0.5)*rz;
99 col *= smoothstep(.8,1.15,rz)*.7+.8;
100 #endif
101
102 #ifndef COLORED
103 col = vec3(dot(col,vec3(.7)));
104 #endif
105
106 #ifdef SHOW_TRIANGLE_NOISE_ONLY
107 col = vec3(triangleNoise(bp));
108 #endif
109
110 fragColor = vec4(col,1.0);
111
112 }