@@ -17,6 +17,9 @@ uniform int maxIterations; // Max iterations per pixel
1717const float max = 4.0 ; // We consider infinite as 4.0: if a point reaches a distance of 4.0 it will escape to infinity
1818const float max2 = max * max ; // Square of max to avoid computing square root
1919
20+ // WebGL shaders for loop iteration limit only const
21+ const int maxIterationsLimit = 20000 ;
22+
2023void main()
2124{
2225 // The pixel coordinates are scaled so they are on the mandelbrot scale
@@ -31,31 +34,29 @@ void main()
3134 // Fc(z) = z^2 + c on the complex numbers c from the plane does not diverge to infinity starting at z = 0
3235 // Here: z = a + bi. Iterations: z -> z^2 + c = (a + bi)^2 + (c.x + c.yi) = (a^2 - b^2 + c.x) + (2ab + c.y)i
3336
34- int iter = 0 ;
35- while (iter < maxIterations)
37+ for (int iter = 0 ; iter < maxIterationsLimit; ++ iter)
3638 {
3739 float aa = a* a;
3840 float bb = b* b;
41+ if (iter >= maxIterations)
42+ {
43+ gl_FragColor = vec4 (0.0 , 0.0 , 0.0 , 1.0 );
44+ return ;
45+ }
3946 if (aa + bb > max2)
40- break ;
47+ {
48+ float normR = float (iter - (iter/ 55 )* 55 )/ 55.0 ;
49+ float normG = float (iter - (iter/ 69 )* 69 )/ 69.0 ;
50+ float normB = float (iter - (iter/ 40 )* 40 )/ 40.0 ;
51+
52+ gl_FragColor = vec4 (sin (normR* PI), sin (normG* PI), sin (normB* PI), 1.0 );
53+ return ;
54+ }
4155
4256 float twoab = 2.0 * a* b;
4357 a = aa - bb + c.x;
4458 b = twoab + c.y;
45-
46- ++ iter;
4759 }
4860
49- if (iter >= maxIterations)
50- {
51- gl_FragColor = vec4 (0.0 , 0.0 , 0.0 , 1.0 );
52- }
53- else
54- {
55- float normR = float (iter - (iter/ 55 )* 55 )/ 55.0 ;
56- float normG = float (iter - (iter/ 69 )* 69 )/ 69.0 ;
57- float normB = float (iter - (iter/ 40 )* 40 )/ 40.0 ;
58-
59- gl_FragColor = vec4 (sin (normR* PI), sin (normG* PI), sin (normB* PI), 1.0 );
60- }
61+ gl_FragColor = vec4 (0.0 , 0.0 , 0.0 , 1.0 );
6162}
0 commit comments