This repository was archived by the owner on Nov 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic.frag
More file actions
235 lines (190 loc) · 6.69 KB
/
dynamic.frag
File metadata and controls
235 lines (190 loc) · 6.69 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#define SHADER_NAME dynamic.frag
precision highp float;
uniform vec2 uResolution;
uniform float uTime;
// Created by inigo quilez - iq/2013
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
//
//-----------------https://www.shadertoy.com/view/MdX3zN-------------------------------------------
//
// Dynamics for quadratic 1D polynomials fc(z)=z²+c
//
// * Orange: the Fatou set Kc.
// * Black: the Julia set Jc.
// * Checkerboard distortion: the Boettcher map phi(z).
// * Checkerboard shadowing: the gradient of the Green's function, log|phi(z)|
// * Blue: the two fixed points.
// * Green, the period 2 fixed points.
// * White: c
// * Yellow: the Koening coordinates
//
// Some theory:
//
// * c (white) belongs to Kc (orange), for these are all connected Julia sets.
//
// * When both fixed points (blue) are in Jc but not in Kc, or in other words, when both points
// are repeling (derivative of fc(z) is bigger than one), c does not belong to the Mandelbrot
// set's main cardioid, but to bulbs of higher period. In that case Kc (orange) is made of several
// branches (as many as the period of the bul)
//
// * When one of the two fixed points (blue dots) is inside Kc, meanins it is attractive (derivative
// of fc(z) < 1), then c belongs to the main cardiod of the Mandelbrot set, and Kc is a single piece
// shape.
//
// * When the period 2 fixed points are always repelling (belong to Jc, not to Kc) except for the sets
// that have c belonging to the period-2 bulb of the Mandelbrot set. In those cases, the green dots
// become attrative and sit inside the orange area Kc.
//
// * The Koening coordinates can only been seen when c belongs to the main cariod of the Madelbrot set
//
//------------------------------------------------------------
// complex number operations
vec2 cadd( vec2 a, float s ) { return vec2( a.x+s, a.y ); }
vec2 cmul( vec2 a, vec2 b ) { return vec2( a.x*b.x - a.y*b.y, a.x*b.y + a.y*b.x ); }
vec2 cdiv( vec2 a, vec2 b ) { float d = dot(b,b); return vec2( dot(a,b), a.y*b.x - a.x*b.y ) / d; }
vec2 csqrt( vec2 z ) { float m = length(z); return sqrt( 0.5*vec2(m+z.x, m-z.x) ) * vec2( 1.0, sign(z.y) ); }
vec2 conj( vec2 z ) { return vec2(z.x,-z.y); }
vec2 cpow( vec2 z, float n ) { float r = length( z ); float a = atan( z.y, z.x ); return pow( r, n )*vec2( cos(a*n), sin(a*n) ); }
//------------------------------------------------------------
float argument( in vec2 p )
{
float f = atan( p.y, p.x );
if( f<0.0 ) f += 6.2831;
f = f/6.2831;
return f;
}
float grid( in vec2 p )
{
vec2 q = 16.0*p;
vec2 r = fract( q );
float fx = smoothstep( 0.05, 0.06, r.x ) - smoothstep( 0.94, 0.95, r.x );
float fy = smoothstep( 0.05, 0.06, r.y ) - smoothstep( 0.94, 0.95, r.y );
return 0.5 + 0.5*mod( floor(q.x)+floor(q.y), 2.0 );
}
float cross( vec2 a, vec2 b )
{
return a.x*b.y - a.y*b.x;
}
bool isInTriangle( in vec2 p, in vec2 a, in vec2 b, in vec2 c )
{
vec3 di = vec3( cross( b - a, p - a ),
cross( c - b, p - b ),
cross( a - c, p - c ) );
return all(greaterThan(di,vec3(0.0)));
}
float distanceToSegment( vec2 a, vec2 b, vec2 p )
{
vec2 pa = p - a;
vec2 ba = b - a;
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
return length( pa - ba*h );
}
vec3 circle( vec3 bcol, vec3 col, in vec2 a, in vec2 b )
{
float rr = 0.04;
vec3 res = mix( bcol, col, 1.0 - smoothstep( rr-0.01, rr, length(a-b) ) );
float f = smoothstep( rr-0.01, rr, length(a-b) ) - smoothstep( rr, rr+0.01, length(a-b) );
return mix( res, vec3(0.0), f );
}
//------------------------------------------------------------
void main()
{
vec2 uv = gl_FragCoord.xy/uResolution;
vec2 p = -1.0 + 2.0*uv;
p.x *= uResolution.x/uResolution.y;
float at = mod( (uTime+.5)/5.0, 8.0 );
vec2 c = vec2(-0.800, 0.100);
c = mix( c, vec2( 0.280,-0.490), smoothstep(0.0,0.1,at) );
c = mix( c, vec2(-0.500,-0.500), smoothstep(1.0,1.1,at) );
c = mix( c, vec2(-0.160, 0.657), smoothstep(2.0,2.1,at) );
c = mix( c, vec2(-0.650, 0.100), smoothstep(3.0,3.1,at) );
c = mix( c, vec2(-0.114, 0.650), smoothstep(4.0,4.1,at) );
c = mix( c, vec2(-0.731, 0.166), smoothstep(5.0,5.1,at) );
c = mix( c, vec2(-0.100,-0.660), smoothstep(6.0,6.1,at) );
c = mix( c, vec2(-0.800, 0.100), smoothstep(7.0,7.1,at) );
// get the 2 fixed points
vec2 one = vec2( 1.0, 0.0 );
vec2 fix1_1 = 0.5*( one + csqrt( one - 4.0*c ) );
vec2 fix1_2 = 0.5*( one - csqrt( one - 4.0*c ) );
vec2 fix2_1 = -(csqrt(-4.0*c-3.0*one)+one)/2.0;
vec2 fix2_2 = (csqrt(-4.0*c-3.0*one)-one)/2.0;
vec2 fix2_3 = -(csqrt( one-4.0*c)-one)/2.0;
vec2 fix2_4 = (csqrt( one-4.0*c)+one)/2.0;
vec2 z = p;
vec2 dz = vec2( 1.0, 0.0 );
vec2 ph = z;
vec2 gr = vec2( log(length(z)), atan(z.y,z.x) );
float t = 0.0;
for( int i=0; i<512; i++ )
{
if( dot(z,z)>10000.0 ) continue;
t += 1.0;
// derivative
dz = 2.0*cmul( z, dz );
// point
z = cmul(z,z) + c;
vec2 a = cdiv(z,z-c);
float s = pow( 0.5, t );
// phi
ph = cmul( ph, cpow(a, s) );
// green
gr.x += log(length(a)) * s;
float aa = atan(a.y,a.x);
if( isInTriangle( z, vec2(0.0), fix1_2, c ) )
{
aa -= sign(aa)*2.0*3.14159;
}
gr.y += aa * s;
}
vec3 col = vec3(1.0,0.65,0.10);
if( t<511.0 )
{
float s = pow( 0.5, t );
vec2 phib = cpow( z, s );
float phiR = length( phib );
float greenR = log(length(z)) * s;
float greenI = argument(z*s);
float d = log( length(z) ) * length(z) / length(dz);
vec2 gradG = -conj(cmul( dz, conj(z) ));
float n = t/50.0;
float sn = -log2(abs(greenR))/50.0;
col = vec3( 0.6 + 0.4*dot(normalize(-gradG),vec2(0.707)) );
col *= vec3( grid( ph ) );
col *= vec3(1.0)*clamp(d*50.0,0.0,1.0);
}
else
{
z = p;
float t = 0.0;
for( int i=0; i<200; i++ )
{
if( length(z-fix1_2)>0.001 )
{
z = cmul(z,z) + c;
t += 1.0;
}
}
vec2 fix = fix1_2;
if( length(2.0*fix1_1)<1.0 ) fix=fix1_1;
if( length(2.0*fix)<1.0 )
{
vec2 ph = cdiv( z - fix, cpow(2.0*fix,t) );
float g = log(length(ph));
float l = 1.0 - 0.1*smoothstep( 0.7, 0.71, sin(48.0*g) );
col += 0.1*(abs(g));
ph = 1.0*vec2( length(ph), atan(ph.y,ph.x)/3.14 );
col *= l;
}
}
// color depending of attractive/repulsive fixed point
col = circle( col, vec3(1.0,1.0,1.0), p, c );
vec3 col2 = vec3(0.0,1.0,0.0);
col = circle( col, col2, p, fix2_1 );
col = circle( col, col2, p, fix2_2 );
col = circle( col, col2, p, fix2_3 );
col = circle( col, col2, p, fix2_4 );
vec3 col1 = vec3(0.0,0.7,1.0);
col = circle( col, col1, p, fix1_1 );
col = circle( col, col1, p, fix1_2 );
gl_FragColor = vec4( col, 1.0 );
}