Debian Codegraph @

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

raw
1 // from https://www.shadertoy.com/view/Md2XR3
2
3 #define PI 3.1415926535897932384626433832795
4
5 void mainImage( out vec4 fragColor, in vec2 fragCoord )
6 {
7 float pulse = 1.; // pulse: on/off
8 float mag = 80.;
9
10 float gs = iResolution.x / 20.;
11 float ar = iResolution.x / iResolution.y;
12 float t =0.2*iTime;
13
14 if (pulse != 0.) {
15 pulse = sqrt( abs( mod( t, .4 ) - .2 ) ) * 16.;
16 mag = 160.;
17 }
18 vec2 s =iResolution.xy/mag+pulse;
19
20 // correct aspect ratio
21 vec2 p =fragCoord.xy/iResolution.x;
22
23 if (pulse != 0.) {
24 p *= s-s/2.; // scale
25 }
26
27 // rotate
28 float sa =sin(t);
29 float ca =clamp(cos(t * 4.),-.9,.9);
30 vec2 rp =vec2( p.x*ca - p.y*sa, p.x*sa + p.y*ca );
31 if (pulse != 0.) { p = rp; }
32 else { p = rp * mag * .1; }
33
34 // calculate the cumulative value of several sine functions
35 float v =sin(p.x+.8*t)+.5*sin(p.y+.8*t)+.5*sin(p.x+p.y+.9*t);
36 p += s/2.*vec2(sin(t/.9),cos(t/.6));
37 v += sin(sqrt(p.x*p.x+p.y*p.y+1.)+t);
38
39 // color blending
40 float R =sin(.2 *PI*v),
41 G =cos(.75*PI*v),
42 B =sin(.9 *PI*v);
43
44 // restricted color palette (nice effect)
45 // code by McRam (https://www.shadertoy.com/view/ld2XRG)
46 R = ceil(R*255. / 8.) * 8. / 256.;
47 G = ceil(G*255. / 16.) * 16. / 256.;
48 B = ceil(B*255. / 8.) * 8. / 256.;
49
50 if(mod(R,16.) < 1.) R =G*.5+.5;
51 vec3 col =vec3(R,G,B);
52
53 // grid
54 col *= 0.4 * 1./length( sin( 1.*.1 * gs*p.x ) );
55 col *= 0.8 * 1./length( sin( ar*.1 * gs*p.y ) );
56
57 // deinterlaced scanlines
58 col *= .33 * length( sin( 5. * p.y * gs ) );
59
60 col =clamp(col,vec3(.0),vec3(1.)); // safe range
61 fragColor = vec4(col,1.);
62 }