Debian Codegraph @

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

raw
1 // See: https://www.shadertoy.com/view/ltjXDW
2
3 /*
4
5 Infinite zoom textures. They've been keeping me amused for years. :)
6
7 This is a trimmed down version of something I wrote some time ago.
8
9 Conceptually, it's the same as Fabrices cool "Infinite Fall" example, with some
10 minor differences. Obviously this version is lacking certain aesthetics and not
11 as functional. I cheated by hardcoding them (8 in all).
12
13 I like trimming down code, but usually set the restriction that the modifications
14 don't reduce the efficiency. I also try to avoid "define"s and so forth. Easier said
15 than done. The textureless version (see below) is under two tweets, but the
16 procedural one is about a hundred characters more.
17
18 I have some nicer examples than this one, so I might put one up at some stage.
19
20 Fabrice Neyret's version:
21 infinite fall - short
22 https://www.shadertoy.com/view/ltjXWW
23
24 */
25
26 void mainImage( out vec4 o, in vec2 p )
27 {
28 float t = iGlobalTime;
29 float c = cos(t), s = sin(t);
30 vec2 R = iResolution.xy;
31 p = (p - R*.5)/R.y * mat2(c, s, -s, c);
32 o = vec4(0.);
33 // Hard coded to 8 layers.
34 for (float i = 0.; i<8.; i++)
35 {
36 // Fractional time component.
37 s = fract((i - t*2.)/8.);
38
39 // Accumulating each layer.
40 //
41 // p*exp2(s*8.) - UV component, based on "s."
42 // i*.9 - A bit of a fudge to mix the layers up a bit.
43 // (.5-abs(s-.5)) - Amplituded component. Half the amplitude, to be precise.
44 //o += N(p*exp2(s*8.) + i*.9) * (.5-abs(s-.5))*.5;
45
46 // Textured version. Used with the greyscale noise texture, but works with
47 // others textures too - after tweaking the UV frequency a bit. My favorite
48 // is the pinkish coral texture.
49
50 // Adding to "o," as suggested by Fabrice.
51 o += texture2D(iChannel0, p*exp2(s*8.)/2e2 + i*.9) * (.5 - abs(s-.5))*.5;
52 }
53 }