-
Notifications
You must be signed in to change notification settings - Fork 0
/
juliasetfractal.txt
70 lines (61 loc) · 1.96 KB
/
juliasetfractal.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
59
60
61
62
63
64
65
66
67
68
69
70
//#ifdef GL_ES
#define MAX_ITER 20
//z starts with an initial value of the pixel(c1) and then you
//add c2 in the iteration which can
//be a constant or mouse position
float fJulia(vec2 c1, vec2 c2){
float l = 0.;
vec2 z = c1;
for(float i=0.;i<float(MAX_ITER);i++) {
if (z.x*z.x + z.y*z.y > 4.) {
return l;
break;
}
float xtemp = z.x*z.x-(z.y*z.y);
z.y = 2.*z.x*z.y + c2.y;
z.x = xtemp + c2.x;
l+=1.;
}
return l;
}
vec3 trueCmap(float n) {
// GLSL has it's own syntax for creating arrays . . .
if (n == float(MAX_ITER)){
vec3 black = vec3(0.,0.,0.);
return black;
}
vec3 cMap[6] = vec3[6](vec3(1.,0.,0.), vec3(1.,0.,1.), vec3(0.,0.,1.), vec3(0.,1.,0.), vec3(1.,1.,0.), vec3(1.,0.5,0.)) ;
//vec3 cMap[3] = vec3[3](vec3(1.,0.,0.), vec3(1.,0.,1.), vec3(0.,0.,1.));//, vec3(0.,1.,0.), vec3(1.,1.,0.), vec3(1.,0.5,0.)) ;
float quotient = float(cMap.length()) * n / float(MAX_ITER);
float lowerIndex = floor(quotient);
float upperIndex = ceil(quotient);
highp int lIndex = int(lowerIndex);
highp int uIndex = int(upperIndex);
float fraction = quotient - lowerIndex;
vec3 c = cMap[lIndex] + fraction * (cMap[uIndex] - cMap[lIndex]);
return c;
}
vec4 nmap(float n) {
vec3 colmap;
if (float(n) <= float(MAX_ITER)) {
float quotient = float(n) / float(MAX_ITER);
float color = clamp(quotient,0.,1.);
if (quotient > 0.5) {
// Close to the mandelbrot set the color changes from green to white
colmap = vec3(0.); //(color,1.,color);
}
else {
colmap = vec3(0.,color,0.);
}
}
return vec4(colmap,1.);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy/iResolution.xy;
float aspect = iResolution.y/iResolution.x;
vec2 p = uv*2.-1.;
p.y*=aspect;
float n = fJulia(p*2.);
fragColor = vec4(trueCmap(n),1.);
}