2 // Fragment shader for drawing the Mandelbrot set
4 // Authors: Dave Baldwin, Steve Koren, Randi Rost
5 // based on a shader by Michael Rivero
7 // Copyright (c) 2002-2005: 3Dlabs, Inc.
9 // See 3Dlabs-License.txt for license information
12 varying vec3 Position;
13 varying float LightIntensity;
15 uniform float MaxIterations;
17 uniform float Xcenter;
18 uniform float Ycenter;
19 uniform vec3 InnerColor;
20 uniform vec3 OuterColor1;
21 uniform vec3 OuterColor2;
25 float real = Position.x * Zoom + Xcenter;
26 float imag = Position.y * Zoom + Ycenter;
27 float Creal = real; // Change this line...
28 float Cimag = imag; // ...and this one to get a Julia set
33 // for (iter = 0.0; iter < MaxIterations && r2 < 4.0; ++iter)
34 for (iter = 0.0; iter < 12 && r2 < 4.0; ++iter)
36 float tempreal = real;
38 real = (tempreal * tempreal) - (imag * imag) + Creal;
39 imag = 2.0 * tempreal * imag + Cimag;
40 r2 = (real * real) + (imag * imag);
43 // Base the color on the number of iterations
50 color = mix(OuterColor1, OuterColor2, fract(iter * 0.05));
52 color *= LightIntensity;
54 gl_FragColor = vec4(color, 1.0);