-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmandel.ocl
35 lines (30 loc) · 1.06 KB
/
mandel.ocl
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
__kernel void mandel(__global uchar* o, float mandpow) {
int z = get_global_id(2);
int y = get_global_id(1);
int x = get_global_id(0);
int zr = get_global_size(2);
int yr = get_global_size(1);
int xr = get_global_size(0);
float scale = 1.2f * 2.0f;
float zf = scale * ((float)z - ((float)zr)/2) / (float)zr;
float yf = scale * ((float)y - ((float)yr)/2) / (float)yr;
float xf = scale * ((float)x - ((float)xr)/2) / (float)xr;
const int maxit = 80;
uchar i;
float lx,ly,lz;
for(i=0,lx=0.0f,ly=0.0f,lz=0.0f;(i<maxit) && (lx*lx+ly*ly+lz*lz) < 2.0f;i++)
{
float r = sqrt(lx*lx + ly*ly + lz*lz);
float theta = atan2(sqrt(lx*lx+ly*ly), lz);
float phi = atan2(ly, lx);
/* These maths from http://www.skytopia.com/project/fractal/mandelbulb.html */
float rpow = pow(r,mandpow);
float newx = rpow * sin(theta*mandpow) * cos(phi*mandpow);
float newy = rpow * sin(theta*mandpow) * sin(phi*mandpow);
float newz = rpow * cos(theta*mandpow);
lx = newx+xf;
ly = newy+yf;
lz = newz+zf;
}
o[z*yr*xr + y*xr + x] = i;
}