-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandelEscape.cl
41 lines (34 loc) · 946 Bytes
/
mandelEscape.cl
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// mandelEscape kernel function
// for 1024x1024 square region
// upto 300 escape iterations
// and infinity beyond distance of 2 from origin
//
//
// Complex multiply
// z->x = z1.x * z2.x - z1.y * z2.y;
// z->y = z1.x * z2.y + z2.x * z1.y;
//
//#pragma OPENCL EXTENSION cl_khr_gl_sharing : enable
__kernel void mandelEscape(__global uint * mandelOut,
const float startX,
const float startY,
const float step)
{
uint gid = get_global_id(0);
float2 f0;
float4 f1;
f0.x = startX + step * (gid % 1024);
f0.y = startY - step * (gid / 1024);
f1.x = 0;
f1.y = 0;
uint mCount = 0;
while(!((f1.x * f1.x + f1.y * f1.y >= 4) || mCount > 299)){
f1.z = f1.x;
f1.w = f1.y;
f1.x = f1.z * f1.z - f1.w * f1.w + f0.x;
f1.y = f1.z * f1.w + f1.z * f1.w + f0.y;
mCount = mCount + 1;
}
mandelOut[gid] = mCount;
}