Strange attractors with OpenCL
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 

80 lines
2.1 KiB

kernel void initialize(size_t width, size_t height, write_only image2d_t output){
size_t x = get_global_id(0);
size_t y = get_global_id(1);
int2 coord = {x, y};
const float xx = x / float(width - 1) - 0.5;
const float yy = y / float(height - 1) - 0.5;
float4 color = {0.066 * xx, 0.1 * yy, 0.1 * yy * xx, 1};
write_imagef(output, coord, color);
}
kernel void hblur(size_t width, size_t height, read_only image2d_t input, write_only image2d_t output){
int x = get_global_id(0);
int y = get_global_id(1);
const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE
| CLK_ADDRESS_NONE
| CLK_FILTER_NEAREST;
float4 c = {0, 0, 0, 0};
const int size = 7;
float weights[] = {0.25, 0.1, 0.1, 0.1, 0.1, 0.1, 0.25};
for(int i = 0; i < size; ++i){
int x2 = (x - size/2 + i + width) % width;
int2 read = {x2, y};
c += read_imagef(input, sampler, read) * weights[i];
}
int2 coord = {x, y};
write_imagef(output, coord, c);
}
kernel void vblur(size_t width, size_t height, read_only image2d_t input, write_only image2d_t output){
int x = get_global_id(0);
int y = get_global_id(1);
const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE
| CLK_ADDRESS_NONE
| CLK_FILTER_NEAREST;
float4 c = {0, 0, 0, 0};
int size = 7;
float weights[] = {0.25, 0.1, 0.1, 0.1, 0.1, 0.1, 0.25};
for(int i = 0; i < size; ++i){
int y2 = (y - size/2 + i + height) % height;
int2 read = {x, y2};
c += read_imagef(input, sampler, read) * weights[i];
}
int2 coord = {x, y};
write_imagef(output, coord, c);
}
kernel void update(size_t width, size_t height, read_only image2d_t input, write_only image2d_t output){
size_t x = get_global_id(0);
size_t y = get_global_id(1);
int2 coord = {x, y};
const sampler_t samplerA = CLK_NORMALIZED_COORDS_FALSE
| CLK_ADDRESS_NONE
| CLK_FILTER_NEAREST;
const float4 w = read_imagef(input, samplerA, coord);
float4 v = w;
const float s = 9.120836;
const float r = 32.799129;
const float b = 2.902814;
const float dt = 0.019997;
v.x += dt * s * (w.y - w.x);
v.y += dt * (w.x * (r - w.z) - w.y);
v.z += dt * (w.x * w.y - b * w.z);
write_imagef(output, coord, v);
}