summaryrefslogtreecommitdiffstats
path: root/src/com/mbien/opencl/demos/fractal/Mandelbrot.cl
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-01-26 23:42:24 +0100
committerMichael Bien <[email protected]>2010-01-26 23:42:24 +0100
commitda609ba8c21e607196daca60b7d994eb2cb6fe4c (patch)
tree06857bf0e15e6c0332f7f9817aa0b0e7b5f7400a /src/com/mbien/opencl/demos/fractal/Mandelbrot.cl
parentac36a9194ff522ea6a0f82cfb22bc438d532ddbb (diff)
initial import of GL-CL Mandelbrot Set example.
Diffstat (limited to 'src/com/mbien/opencl/demos/fractal/Mandelbrot.cl')
-rw-r--r--src/com/mbien/opencl/demos/fractal/Mandelbrot.cl44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/com/mbien/opencl/demos/fractal/Mandelbrot.cl b/src/com/mbien/opencl/demos/fractal/Mandelbrot.cl
new file mode 100644
index 0000000..e6583f4
--- /dev/null
+++ b/src/com/mbien/opencl/demos/fractal/Mandelbrot.cl
@@ -0,0 +1,44 @@
+/**
+ * For a description of this algorithm please refer to
+ * http://en.wikipedia.org/wiki/Mandelbrot_set
+ * @author Michael Bien
+ */
+kernel void mandelbrot(
+ global uint *output,
+ const int width, const int height,
+ const float x0, const float y0,
+ const float x1, const float y1,
+ global uint *colorMap, const int colorMapSize, const int maxIterations) {
+
+ unsigned int ix = get_global_id(0);
+ unsigned int iy = get_global_id(1);
+
+ float r = x0 + ix * (x1-x0) / width;
+ float i = y0 + iy * (y1-y0) / height;
+
+ float x = 0;
+ float y = 0;
+
+ float magnitudeSquared = 0;
+ int iteration = 0;
+
+ while (magnitudeSquared < 4 && iteration < maxIterations) {
+ float x2 = x*x;
+ float 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 {
+ float alpha = (float)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