Debian Codegraph @

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

raw
1 // See: https://www.shadertoy.com/view/Xdl3D2
2
3 const float tau = 6.28318530717958647692;
4
5 // Gamma correction
6 #define GAMMA (2.2)
7
8 vec3 ToLinear( in vec3 col )
9 {
10 // simulate a monitor, converting colour values into light values
11 return pow( col, vec3(GAMMA) );
12 }
13
14 vec3 ToGamma( in vec3 col )
15 {
16 // convert back into colour values, so the correct light will come out of the monitor
17 return pow( col, vec3(1.0/GAMMA) );
18 }
19
20 vec4 Noise( in ivec2 x )
21 {
22 return texture( iChannel0, (vec2(x)+0.5)/256.0, -100.0 );
23 }
24
25 vec4 Rand( in int x )
26 {
27 vec2 uv;
28 uv.x = (float(x)+0.5)/256.0;
29 uv.y = (floor(uv.x)+0.5)/256.0;
30 return texture( iChannel0, uv, -100.0 );
31 }
32
33
34 void mainImage( out vec4 fragColor, in vec2 fragCoord )
35 {
36 vec3 ray;
37 ray.xy = 2.0*(fragCoord.xy-iResolution.xy*.5)/iResolution.x;
38 ray.z = 1.0;
39
40 float offset = iTime*.5;
41 float speed2 = (cos(offset)+1.0)*2.0;
42 float speed = speed2+.1;
43 offset += sin(offset)*.96;
44 offset *= 2.0;
45
46
47 vec3 col = vec3(0);
48
49 vec3 stp = ray/max(abs(ray.x),abs(ray.y));
50
51 vec3 pos = 2.0*stp+.5;
52 for ( int i=0; i < 20; i++ )
53 {
54 float z = Noise(ivec2(pos.xy)).x;
55 z = fract(z-offset);
56 float d = 50.0*z-pos.z;
57 float w = pow(max(0.0,1.0-8.0*length(fract(pos.xy)-.5)),2.0);
58 vec3 c = max(vec3(0),vec3(1.0-abs(d+speed2*.5)/speed,1.0-abs(d)/speed,1.0-abs(d-speed2*.5)/speed));
59 col += 1.5*(1.0-z)*c*w;
60 pos += stp;
61 }
62
63 fragColor = vec4(ToGamma(col),1.0);
64 }