summaryrefslogtreecommitdiff
path: root/live_play/kernel.c
blob: e572a48c8fcced53cd59a7ff9eb53d7c1dc1b012 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//#include <math.h>
#define PI 3.141592653589793115997963468544185161590576171875

double cosecant_single(double a, double b) { return a / sin(b); }
double secant_single(double a, double b) { 
  //double killme = (double)floor(b / (PI / 2.0)) * (double)(PI / 2.0);
  //return a / sin(killme); 
  //return a / sin((PI / 2.0));
  //return a / sin(PI);
  return a / sin(-PI);
}


__kernel void render_frame(__global unsigned int *frame_output, __global double *mask, 
    double x_step, double y_step,
    double x_start, double y_start,
    unsigned int iterations, unsigned int escape, double ratio) {  
  unsigned int result;
  double x = (get_global_id(0) * x_step) + x_start;
  double y = (get_global_id(1) * y_step) + y_start;
  size_t img_index = (get_global_id(1) * get_global_size(1)) + get_global_id(0);

  unsigned int iter;

    
  
  for(iter = 0; iter < iterations; iter++) { 
    double next_x;
    double r = mask[img_index];
    next_x = (r * cosecant_single(x, y)) + ((1 - r) * secant_single(x, y));
    y = (r * cosecant_single(y, x)) + ((1 - r) * secant_single(y, x));
    x = next_x;
    if((pow(x, 2) + pow(y, 2)) >= escape) break;
  }
  

  
  frame_output[img_index] = iter;
  //frame_output[img_index] = mask[img_index] * 255;
}