I've written a Mandelbrot viewer with zoom using SharpGL (C# implementation of OpenGL). It works fine but after 17 zooms (double scale each zoom) it starts to pixelate pretty badly. I have almost identical code written in c# directly, which doesn't have this problem.
I have tried setting the floats to highp in the fragment shader in case it was a precision problem, but that hasn't made any different. Here is my fragment shader:
#version 400 core
out vec4 out_Color;
in vec4 gl_PointCoord;
in vec4 pixCoord;
uniform float max;
uniform float scale;
uniform float[2] center;
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main(void) {
highp vec2 z,c,p;
vec3 tcolor;
float hue,norm,colorfix,hue2;
highp float x,y;
p.x = pixCoord.x;
p.y = pixCoord.y;
c.x = (p.x) / scale+center[0];
c.y = (p.y) / scale-center[1];
int i;
z = c;
for(i=0; i<max; i++) {
x = (z.x * z.x - z.y * z.y) + c.x;
y = (z.y * z.x + z.x * z.y) + c.y;
if((x * x + y * y) > 4.0) break;
z.x = x;
z.y = y;
}
if (i >= max)
out_Color = vec4(0.0,0.0,0.0, 1.0);
else {
norm = sqrt(x*x+y*y);
colorfix = max / (log(2*(scale))+1);
hue = i + 1 - log(log(norm)/log(2))/log(2);
hue2 = mod((0.8 * colorfix + hue) , colorfix) / colorfix;
tcolor = hsv2rgb(vec3(hue2,0.6,1.0));
out_Color = vec4(tcolor, 1.0);
}
}
I have tried just using black and red in case the smooth color calculations were causing some trouble but that didn't change anything.
Scale is set in the c# sharp program and is just a power of 2 for the zoom, so around 2^17 is where it starts to be noticeable.
center is the real center of image in the complex plane.