-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuns.glsl
70 lines (48 loc) · 1.52 KB
/
suns.glsl
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
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 resolution;
uniform float time;
struct Ray {
vec3 o;
vec3 d;
};
// dueling mandelbulbs
// @acaudwell
// http://www.fractalforums.com/mandelbulb-implementation/realtime-renderingoptimisations/
float mandelbulb(in vec3 p, float power) {
float dr = 1.0;
float r = length(p);
vec3 c = p;
for(int i=0; i<2; i++) {
float zo0 = asin(p.z / r);
float zi0 = atan(p.y, p.x);
float zr = pow(r, power-1.0);
float zo = (zo0) * power;
float zi = (zi0) * power;
float czo=cos(zo);
dr = zr * dr * power + 1.0;
zr *= r;
p = zr * vec3(czo*cos(zi), czo*sin(zi), sin(zo));
p += c;
r = length(p);
}
return 0.5 * r * log(r) / r;
}
void main() {
vec2 p = ((gl_FragCoord.xy / resolution.xy) * 2.0 - 1.0) * 2.5;
float t = time;
Ray ray1;
ray1.o = vec3(0.0);
ray1.d = normalize( vec3((p - 1.5*vec2(sin(t-2.0), cos(t+1.0))) * vec2(resolution.x/resolution.y, 1.0), 1.0 ) );
Ray ray2;
ray2.o = vec3(0.0);
ray2.d = normalize( vec3((p - 1.5*vec2(cos(-t),sin(t))) * vec2(resolution.x/resolution.y, 1.0), 1.0 ) );
ray1.d.xy = vec2( ray1.d.x * cos(t) - ray1.d.y * sin(t), ray1.d.x * sin(t) + ray1.d.y * cos(t));
ray2.d.xy = vec2( ray2.d.x *cos(t) - ray2.d.y * sin(t), ray2.d.x * sin(t) + ray2.d.y * cos(t));
float m1 = mandelbulb(ray1.o + ray1.d, abs(cos(t)*13.0));
float m2 = mandelbulb(ray2.o + ray2.d, abs(sin(t)*13.0));
float f = pow(max(m1,m2) , abs(m1-m2));
vec3 c = m1 > m2 ? vec3(0.0, 0.05, 0.2) : vec3(0.2, 0.05, 0.0);
gl_FragColor = vec4(c*f, 1.0);
}