I cleaned my openCL code.
//Check if choosen point is in MSet
bool isInMSet(
const float2 c,
const uint minIter,
const uint maxIter,
const float escapeOrbit)
{
int iter = 0;
float2 z = 0.0;
if( !(((c.x-0.25)*(c.x-0.25) + (c.y * c.y))*(((c.x-0.25)*(c.x-0.25) + (c.y * c.y))+(c.x-0.25)) < 0.25* c.y * c.y)) //main cardioid
{
if( !((c.x+1.0) * (c.x+1.0) + (c.y * c.y) < 0.0625)) //2nd order period bulb
{
if (!(( ((c.x+1.309)*(c.x+1.309)) + c.y*c.y) < 0.00345)) //smaller bulb left of the period-2 bulb
{
if (!((((c.x+0.125)*(c.x+0.125)) + (c.y-0.744)*(c.y-0.744)) < 0.0088)) // smaller bulb bottom of the main cardioid
{
if (!((((c.x+0.125)*(c.x+0.125)) + (c.y+0.744)*(c.y+0.744)) < 0.0088)) //smaller bulb top of the main cardioid
{
while( (iter < maxIter) && (z.x*z.x + z.y*z.y < escapeOrbit) ) //Bruteforce check
{
z = (float2)(z.x * z.x - z.y * z.y, (z.x * z.y * 2.0)) + c;
iter++;
}
if( (iter > minIter) && (iter < maxIter))
{
return false;
}
}
}
}
}
}
return true;
}
//Main kernel
__kernel void buddhabrot(
const float realMin,
const float realMax,
const float imaginaryMin,
const float imaginaryMax,
const uint minIter,
const uint maxIter,
const uint width,
const uint height,
const float escapeOrbit,
const uint4 minColor,
const uint4 maxColor,
__global float2* randomXYBuffer,
__global uint4* outputBuffer)
{
float2 rand = randomXYBuffer[get_global_id(0)];
const float deltaReal = (realMax - realMin);
const float deltaImaginary = (imaginaryMax - imaginaryMin);
//mix(a,b,c) = a + (b-a)*c //(c must be in the range 0.0 ... 1.0
float2 c = (float2)(mix(realMin, realMax, rand.x) , mix(imaginaryMin, imaginaryMax, rand.y));
if( isInMSet(c, minIter, maxIter, escapeOrbit) == false)
{
int x, y;
int iter = 0;
float2 z = 0.0;
while( (iter < maxIter) && ((z.x*z.x+z.y*z.y) < escapeOrbit) )
{
z = (float2)(z.x * z.x - z.y * z.y, (z.x * z.y * 2.0)) + c;
x = (width * (z.x - realMin) / deltaReal);
y = (height * (z.y - imaginaryMin) / deltaImaginary);
if( (iter > minIter) && (x>0) && (y>0) && (x<width) && (y<height) )
{
if( (iter > minColor.x) && (iter < maxColor.x) ) { outputBuffer[x + (y * width)].x++; }
if( (iter > minColor.y) && (iter < maxColor.y) ) { outputBuffer[x + (y * width)].y++; }
if( (iter > minColor.z) && (iter < maxColor.z) ) { outputBuffer[x + (y * width)].z++; }
}
iter++;
}
}
}
__kernel void xorshift(
uint s1,
uint s2,
const int bufferSize,
__global float2* randomXYBuffer
)
{
uint st;
for(int i=0; i < bufferSize; i++)
{
st = s1 ^ (s1 << 11);
s1 = s2;
s2 = s2 ^ (s2 >> 19) ^ ( st ^ (st >> 18));
randomXYBuffer[i] = (float2)((float)st / UINT_MAX,(float)s1 / UINT_MAX);
}
}
Now i'll be able to test some other idea
