132001f49Smrg//
232001f49Smrg// Fragment shader for drawing the Mandelbrot set
332001f49Smrg//
432001f49Smrg// Authors: Dave Baldwin, Steve Koren, Randi Rost
532001f49Smrg//          based on a shader by Michael Rivero
632001f49Smrg//
732001f49Smrg// Copyright (c) 2002-2005: 3Dlabs, Inc.
832001f49Smrg//
932001f49Smrg// See 3Dlabs-License.txt for license information
1032001f49Smrg//
1132001f49Smrg
1232001f49Smrgvarying vec3  Position;
1332001f49Smrgvarying float LightIntensity;
1432001f49Smrg
1532001f49Smrguniform float MaxIterations;
1632001f49Smrguniform float Zoom;
1732001f49Smrguniform float Xcenter;
1832001f49Smrguniform float Ycenter;
1932001f49Smrguniform vec3  InnerColor;
2032001f49Smrguniform vec3  OuterColor1;
2132001f49Smrguniform vec3  OuterColor2;
2232001f49Smrg
2332001f49Smrgvoid main()
2432001f49Smrg{
2532001f49Smrg    float   real  = Position.x * Zoom + Xcenter;
2632001f49Smrg    float   imag  = Position.y * Zoom + Ycenter;
2732001f49Smrg    float   Creal = real;   // Change this line...
2832001f49Smrg    float   Cimag = imag;   // ...and this one to get a Julia set
2932001f49Smrg
3032001f49Smrg    float r2 = 0.0;
3132001f49Smrg    float iter;
3232001f49Smrg
3332001f49Smrg//    for (iter = 0.0; iter < MaxIterations && r2 < 4.0; ++iter)
3432001f49Smrg    for (iter = 0.0; iter < 12.0 && r2 < 4.0; ++iter)
3532001f49Smrg    {
3632001f49Smrg        float tempreal = real;
3732001f49Smrg
3832001f49Smrg        real = (tempreal * tempreal) - (imag * imag) + Creal;
3932001f49Smrg        imag = 2.0 * tempreal * imag + Cimag;
4032001f49Smrg        r2   = (real * real) + (imag * imag);
4132001f49Smrg    }
4232001f49Smrg
4332001f49Smrg    // Base the color on the number of iterations
4432001f49Smrg
4532001f49Smrg    vec3 color;
4632001f49Smrg
4732001f49Smrg    if (r2 < 4.0)
4832001f49Smrg        color = InnerColor;
4932001f49Smrg    else
5032001f49Smrg        color = mix(OuterColor1, OuterColor2, fract(iter * 0.05));
5132001f49Smrg
5232001f49Smrg    color *= LightIntensity;
5332001f49Smrg
5432001f49Smrg    gl_FragColor = vec4(color, 1.0);
5532001f49Smrg}
56