diff options
author | Michael Bien <[email protected]> | 2010-04-12 22:27:03 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-04-12 22:27:03 +0200 |
commit | 2c85c416d85205ab98b33e1a0b0daab32d4d81ff (patch) | |
tree | 4187ba06dec81da46495a300bb4f914e931f0c58 /src/com/jogamp/opencl/demos/fractal/Mandelbrot.cl | |
parent | b51f2e1c254cdd74c9e43904c62694f64e6ae7e6 (diff) |
changes due to package renaming in jocl.
Diffstat (limited to 'src/com/jogamp/opencl/demos/fractal/Mandelbrot.cl')
-rw-r--r-- | src/com/jogamp/opencl/demos/fractal/Mandelbrot.cl | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/com/jogamp/opencl/demos/fractal/Mandelbrot.cl b/src/com/jogamp/opencl/demos/fractal/Mandelbrot.cl new file mode 100644 index 0000000..640c775 --- /dev/null +++ b/src/com/jogamp/opencl/demos/fractal/Mandelbrot.cl @@ -0,0 +1,51 @@ +#ifdef DOUBLE_FP + #pragma OPENCL EXTENSION cl_khr_fp64 : enable + typedef double varfloat; +#else + typedef float varfloat; +#endif + +/** + * For a description of this algorithm please refer to + * http://en.wikipedia.org/wiki/Mandelbrot_set + * @author Michael Bien + */ +kernel void mandelbrot( + const int width, const int height, + const varfloat x0, const varfloat y0, + const varfloat rangeX, const varfloat rangeY, + global uint *output, global uint *colorMap, + const int colorMapSize, const int maxIterations) { + + unsigned int ix = get_global_id(0); + unsigned int iy = get_global_id(1); + + varfloat r = x0 + ix * rangeX / width; + varfloat i = y0 + iy * rangeY / height; + + varfloat x = 0; + varfloat y = 0; + + varfloat magnitudeSquared = 0; + int iteration = 0; + + while (magnitudeSquared < 4 && iteration < maxIterations) { + varfloat x2 = x*x; + varfloat y2 = y*y; + y = 2 * x * y + i; + x = x2 - y2 + r; + magnitudeSquared = x2+y2; + iteration++; + } + + if (iteration == maxIterations) { + output[iy * width + ix] = 0; + }else { + varfloat alpha = (varfloat)iteration / maxIterations; + int colorIndex = (int)(alpha * colorMapSize); + output[iy * width + ix] = colorMap[colorIndex]; + // monochrom + // output[iy * width + ix] = 255*iteration/maxIterations; + } + +}
\ No newline at end of file |