-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathglobe_base.frag
More file actions
executable file
·131 lines (88 loc) · 2.6 KB
/
globe_base.frag
File metadata and controls
executable file
·131 lines (88 loc) · 2.6 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#define MAX_STEPS 100
#define FAR_DISTANCE 4.
#define MIN_DISTANCE 0.0001
#define SPEED .8
float n21(vec2 p) {
return fract(sin(p.x*123.43 + p.y*4563.234) * 46832.4);
}
float rand(vec2 n) {
return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
}
float noise(vec2 p){
vec2 ip = floor(p);
vec2 u = fract(p);
u = u*u*(3.0-2.0*u);
float res = mix(
mix(rand(ip),rand(ip+vec2(1.0,0.0)),u.x),
mix(rand(ip+vec2(0.0,1.0)),rand(ip+vec2(1.0,1.0)),u.x),u.y);
return res*res;
}
const mat2 m2 = mat2(0.8,-0.6,0.6,0.8);
float fbm2( in vec2 p ){
float f = 0.0;
f += 0.5000*noise( p ); p = m2*p*2.02;
f += 0.2500*noise( p ); p = m2*p*2.03;
f += 0.1250*noise( p ); p = m2*p*2.01;
f += 0.0625*noise( p );
return f/0.9375;
}
vec3 getTexture(vec2 uv) {
vec3 col = vec3(0.);
float size = 400.;
uv *= size;
vec2 id = floor(uv);
uv = fract(uv);
float n = fbm2(id/30. + vec2(-iTime/8.*SPEED, iTime/4.*SPEED));
col += n * vec3(0.9, 0.3, .1);
return col;
}
void mainImage(out vec4 fragColor, in vec2 fragCoords) {
vec2 uv = fragCoords / iResolution.xy;
uv -= .5;
uv.x *= iResolution.x / iResolution.y;
vec2 guv = uv;
uv.y += 1.2 + sin(iTime)*.0099;
vec3 col = vec3(0.0);
float a = 2.5;
vec3 ro = vec3(0. + sin(a), 0.+cos(a), -1);
vec3 lookat = vec3(0.05, .0, 0.);
float zoom = 22.;
vec3 f = normalize(lookat - ro);
vec3 r = normalize(cross(vec3(0., 1., 0), f));
vec3 u = cross(f, r);
vec3 c = ro + f * zoom;
vec3 i = c + uv.x*r + uv.y*u;
vec3 rd = normalize(i - ro);
vec3 p = vec3(0., 0., 0.);
float d = length(cross(rd, p - ro))/length(rd);
float glowMask = 1. - mix(smoothstep(.20, .02, d*1.45), .0, step(d, .1));
vec3 ds, dt;
float sd;
int steps;
for(int i = 0 ; i < MAX_STEPS ; i++) {
p = ro + rd * ds;
steps += 1;
sd = length(p) - .0999;
ds += sd;
if (abs(sd) < MIN_DISTANCE || sd > FAR_DISTANCE) {
break;
}
}
vec3 globe = vec3(0.);
if (abs(sd) < MIN_DISTANCE) {
// p.x += iTime/20.;
float x = acos(p.y/length(p));
float y = atan(p.z, p.x);
vec2 uv = vec2(x, y);
globe += smoothstep(.0, 1., clamp(float(steps)/30., 0., 1.))*.5*vec3(0., .5, 0.);
globe += getTexture(uv);
}
globe += (1. - glowMask) * vec3(0., 1., 0.);
col += globe;
// col *= 1. - smoothstep(.3, .4, length(guv));
d = length(guv);
//col *= step(d, .4);
vec3 frame = (step(d, .41) - step(d, .40)) * vec3(.8);
//col += frame;
fragColor = vec4(col, 1.);
}