aboutsummaryrefslogtreecommitdiff
path: root/cl/mandelbrot.cl
blob: 8617ae5b599fbd6f71194112e94e64d73544051e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
__kernel void fractal_gen(
	__global unsigned char *buffer,
	const unsigned int size,
	const unsigned long iterations)
{
	unsigned int x = get_global_id(0);
	unsigned int y = get_global_id(1);
	unsigned long i = 0;

	float a = -2.5+(((float)x)/size)*3.5;
	float b = -1.75+(((float)y)/size)*3.5;

	float2 z = (0.0, 0.0);

	for (i = 0; i < iterations; i++) {
		// if abs(z) > 2
		if (z.x*z.x + z.y*z.y > 4)
			break;

		float oldx = z.x;
		z.x = z.x*z.x - z.y*z.y + a;
		z.y = 2*oldx*z.y + b;
	}
	buffer[(size*y)+x] = (i*255)/iterations;
}