-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbg_stars.frag
executable file
·66 lines (45 loc) · 1.37 KB
/
bg_stars.frag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#define PI 3.1415
#define PI2 PI * 2.;
float N21(vec2 p) {
return fract(sin(p.x * 132.33 + p.y*1433.43) * 55332.33);
}
vec3 starsLayer(vec2 ouv) {
vec3 col = vec3(0.);
vec2 uv = fract(ouv) - .5;
float d;
for(int x = -1 ; x <= 1; x++) {
for(int y = -1 ; y <= 1; y++) {
vec2 offset = vec2(x,y);
vec2 id = floor(ouv) + offset;
float n = N21(id);
if (n > .6) {
float n1 = fract(n*123.432);
float n2 = fract(n*1234.2432);
float size = .01 + 0.05 * (n1 - .5);
vec2 shift = vec2(n1 - .5, n2 - .5);
d = max(d, size/length(uv - offset + shift));
}
}
}
return col + d;
}
vec3 backgroundStars(vec2 uv) {
vec3 col = vec3(0.);
float t = iTime * 0.3;
float layers = 3.;
for(float i = 0. ; i < 1. ; i+= 1./layers) {
float depth = fract(i + t);
float scale = mix(20., .5, depth);
float fade = depth * smoothstep(1., .9, depth);
col += starsLayer(uv * scale + i * 456.32) * fade;
}
return col;
}
void mainImage(out vec4 fragColor, in vec2 fragCoords) {
vec2 uv = fragCoords.xy / iResolution.xy;
uv -= .5;
uv.x *= iResolution.x / iResolution.y;
vec3 col = vec3(0.);
col += backgroundStars(uv + sin(iTime/2.));
fragColor = vec4(col, 1.);
}