diff options
Diffstat (limited to 'opencl/mandelbrot_calc.c')
-rw-r--r-- | opencl/mandelbrot_calc.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/opencl/mandelbrot_calc.c b/opencl/mandelbrot_calc.c new file mode 100644 index 0000000..19abc8f --- /dev/null +++ b/opencl/mandelbrot_calc.c @@ -0,0 +1,35 @@ +__kernel void mandelbrot_calc(const __global double2 *c_pt, + __global unsigned int *out_it, + const unsigned int max_iterations) +{ + const int id = get_global_id(0); + const double2 opt = c_pt[id]; + + double2 pt = opt; + double tmp = pt.x * pt.y; + unsigned int iterations = 0; + + double q = (pt.x - 0.25) * (pt.x - 0.25) + pt.y * pt.y; + if (q * (q + (pt.x - 0.25)) <= 0.25 * pt.y * pt.y) + iterations = max_iterations; + + while (iterations < max_iterations) { + pt *= pt; + + if (pt.x + pt.y > 4.0) + break; + + pt.x = pt.x - pt.y; + pt.y = 2 * tmp; + pt += opt; + tmp = pt.x * pt.y; + + ++iterations; + } + + if (iterations == max_iterations) + out_it[id] = 0; + else + out_it[id] = ((iterations & 0xFF) << 16) | ((iterations & 0x07) << 6); +} + |