Debian Codegraph @

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

raw
1 // Taken from https://www.shadertoy.com/view/Mlf3WX
2
3 // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
4 // Created by S.Guillitte
5
6 const mat2 m2 = mat2(.8,.6,-.6,.8);
7
8 float stars(in vec2 p){
9 vec2 z = p;
10 p=floor(p*5.)/5.+0.1;
11 float r = 80.*dot(z-p,z-p);
12 z=p;
13 for( int i=0; i< 3; i++ )
14 {
15 z=m2*z*1.1+1.3;
16 z+=15.*sin(z+3.*sin(p.yx));
17 }
18 return clamp(2.5-length(z),0.,1.)*exp(-r);
19 }
20
21 float noise(in vec2 p){
22
23 float res=0.;
24 float f=1.;
25 for( int i=0; i< 2; i++ )
26 {
27 p=m2*p*f+4.3;
28 f*=1.1;
29 res+=(sin(p+sin(p.yx))).x;
30 }
31 return (res/3.);
32 }
33
34 float fbm(in vec2 p){
35
36 float res=0.;
37 float f=1.;
38 for( int i=0; i< 5; i++ )
39 {
40 f*=2.;
41 res+=noise(f*p)/f;
42 }
43 return res;
44 }
45
46 void mainImage( out vec4 fragColor, in vec2 fragCoord )
47 {
48 vec2 p = 15.*(-iResolution.xy+2.0*fragCoord.xy)/iResolution.y;
49 float f = stars(p);
50 p+=.8*iTime;
51 vec3 col = vec3(f*f*f,f*f*.8,f*.8);
52 f= clamp(fbm(p*.1),0.,1.);
53 if(f>.1)col =vec3(f*f*f,f*f,f);
54 else col = mix(col,vec3(f*f*f,f*f,f),10.*f);
55
56 fragColor = vec4(col,1.0);
57 }