// min/max for the real coordinate system viewport uniform float minReal; uniform float maxReal; // min/max for the imaginary coordinate system viewport uniform float minImag; uniform float maxImag; // number of iterations to determine if the pixel // is in the set or not uniform int iterations; // julia set constant k uniform vec2 k; // Graphical Effects // color that highlights the BG uniform vec3 bgcolor; // color that highlights the FG uniform vec3 fgcolor; // Utilities // Lerping float lerp(float a, float b, float ratio) { return a * (1.0-ratio) + b * ratio; } vec2 lerp2(vec2 a, vec2 b, float ratio) { return a * (1.0-ratio) + b * ratio; } void main() { // The complex constant c vec2 c = vec2(lerp(minReal, maxReal, gl_TexCoord[0].x), lerp(minImag, maxImag, gl_TexCoord[0].y)); // declaration of the iterative obj Z vec2 z; // funciton of a mandelbrot set is as such: // Zn+1 = Zn^2 + c // We determine if Zn approaches infinity to // determine whether or not the ucrrent point/pixel // is in the set or not. bool isInside = true; int iIterations = 0; float distance = 0.0; z = c; for (int i=1; i 4.0) { // We're approaching infinity! // This is not in the set iIterations = i; isInside = false; break; } } if (isInside) { // in the set float invDist = pow(1.0 - (distance/4.0), 32.0); gl_FragColor = vec4(fgcolor * invDist,1.0); } else { // out of the set gl_FragColor = vec4(bgcolor * float(iIterations)/float(iterations),1.0); } }