-
Notifications
You must be signed in to change notification settings - Fork 0
/
shadertoy.txt
58 lines (53 loc) · 1.71 KB
/
shadertoy.txt
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
//FRAGMENT SHADER
#ifdef GL_ES
precision mediump float;
#endif
#define RE_START -2.
//or float x = 2.0;
//or float x - float(2);
#define RE_END 1.
#define IM_START -1.
#define IM_END 1.
#define MAX_ITER 359
//fragCoord is current pixel
//main loops the entire program every pixel
//vec2 simpleComplex(vec2 xy) {
// vec2 result;
// result.x = (RE_START + (xy.x/iResolution.x) * float(RE_END - RE_START));
// result.y = (IM_START + (xy.y/iResolution.y) * float(IM_END - IM_START));
// return result;
//}
int mbrot(vec2 c) {
vec2 zed;
zed.x = 0.0;
zed.y = 0.0;
int n = 0;
//https://www.varsitytutors.com/hotmath/hotmath_help/topics/absolute-value-complex-number
while (sqrt(pow(zed.x,2.0) + pow(zed.y,2.0)) <= 2.0 && n < MAX_ITER) {
//zed = zed*zed + c;
zed = vec2 (pow(zed.x,2.0)-pow(zed.y,2.0),2.0 *zed.x * zed.y);
zed.x = (zed.x + c.x);
zed.y = (zed.y + c.y);
//http://mathworld.wolfram.com/ComplexAddition.html
n+=1;
}
return n;
}
//function from @Nemes#8370
vec4 hue2rgb(float hue) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(hue + K.xyz) * 6.0 - K.www);
return vec4(clamp(p - K.xxx, 0.0, 1.0), 1.0);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
fragColor = vec4(0.,0.,0.,1.)
vec2 uv = fragCoord.xy/iResolution.xy;
float aspect = iResolution.y/iResolution.x;
vec2 p = uv*2.-1.; // transform uv range(0-1) to be centered and normalized(-1-1)
p.y*=aspect;
int n = mbrot(p*2.); // *2. is the zoom value to create a variable for controlled by GUI
float B = float(n)*8./float(MAX_ITER);
//float B = float(n)/float(MAX_ITER);
vec4 color = hue2rgb(B);
fragColor = color;
}