Debian Codegraph @

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

raw
1 //See: https://www.shadertoy.com/view/ltl3DX
2
3 // ----------------------------------------------------------------------------------------
4 // "DotDotDot" by Antoine Clappier - March 2015
5 //
6 // Licensed under a Creative Commons Attribution-ShareAlike 4.0 International License
7 // http://creativecommons.org/licenses/by-sa/4.0/
8 // ----------------------------------------------------------------------------------------
9
10 // An exercise in seamless loop and smooth animation. Proved to be more difficult than expected!
11 // The right solution was to use an exponential scaling that provides a nice acceleration
12 // while maintaining the same tangents at the beginning and end of the loop.
13
14 const float ShutterSpeed = 1.0/60.0;
15
16 const float LoopS = 3.0;
17 const float Radius = 0.53;
18 const float Scale0 = 0.6;
19 const float ExpF = 4.05;
20 const float Spower = 9.0;
21
22
23 vec3 Render(vec2 pQ, float pT)
24 {
25 float T = fract(pT / LoopS);
26
27 // Transform:
28 float Scale = Scale0*exp(ExpF*T);
29
30 float Sgn = sign(fract(0.5*pT/LoopS) - 0.5);
31 float Cs = cos(Sgn*T);
32 float Sn = sin(Sgn*T);
33
34 vec2 Qt = (1.0 + Scale*pQ*mat2(Cs, -Sn, Sn, Cs)) / 2.0;
35
36 // Dot grid:
37 vec2 Gf = 2.0*fract(Qt) - 1.0;
38 float D = step(length(Gf), Radius + 0.6*pow(T, Spower));
39
40 // Disk clip:
41 D *= step(length(Qt-0.5), 0.5*Radius*exp(ExpF));
42
43 return vec3(D);
44 }
45
46
47
48
49 void mainImage( out vec4 fragColor, in vec2 fragCoord )
50 {
51 float Ratio = 0.5*min(iResolution.x, iResolution.y);
52 vec2 UV = (fragCoord.xy - iResolution.xy/2.0) / Ratio;
53 // Render scene in linear space
54 fragColor = vec4(Render(UV, iGlobalTime), 1.0);
55 }