Joshua Moerman
11 years ago
6 changed files with 53 additions and 149 deletions
@ -1,12 +1,8 @@ |
|||||
#version 330 |
#version 330 |
||||
|
|
||||
uniform sampler2D tex; |
|
||||
|
|
||||
in vec2 tex_coord_int; |
|
||||
|
|
||||
out vec4 fragColor; |
out vec4 fragColor; |
||||
|
in float mx; |
||||
|
|
||||
void main(){ |
void main(){ |
||||
// fragColor = texture(tex, tex_coord_int); |
fragColor = mix(0.7 * vec4(0.3, 0.1, 0.01, 1.0), vec4(0.0, 0.0, 0.4, 1.0), mx); |
||||
fragColor = vec4(0.5) + 0.5*sin(0.1 * texture(tex, tex_coord_int)); |
|
||||
} |
} |
||||
|
@ -1,11 +1,10 @@ |
|||||
#version 330 |
#version 330 |
||||
|
|
||||
in vec4 position; |
in vec4 position; |
||||
in vec2 tex_coord; |
out float mx; |
||||
|
|
||||
out vec2 tex_coord_int; |
|
||||
|
|
||||
void main(){ |
void main(){ |
||||
tex_coord_int = tex_coord; |
gl_Position = vec4(1); |
||||
gl_Position = position; |
gl_Position.xy = 0.04*position.xy; |
||||
|
mx = cos(0.1*position.z); |
||||
} |
} |
||||
|
@ -1,80 +1,14 @@ |
|||||
|
|
||||
kernel void initialize(size_t width, size_t height, write_only image2d_t output){ |
kernel void update(float s, float r, float b, float dt, __global float4* buffer){ |
||||
size_t x = get_global_id(0); |
size_t i = get_global_id(0); |
||||
size_t y = get_global_id(1); |
|
||||
|
|
||||
int2 coord = {x, y}; |
const float4 w = buffer[i]; |
||||
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; |
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.x += dt * s * (w.y - w.x); |
||||
v.y += dt * (w.x * (r - w.z) - w.y); |
v.y += dt * (w.x * (r - w.z) - w.y); |
||||
v.z += dt * (w.x * w.y - b * w.z); |
v.z += dt * (w.x * w.y - b * w.z); |
||||
|
|
||||
write_imagef(output, coord, v); |
buffer[i] = v; |
||||
} |
} |
||||
|
|
||||
|
Reference in new issue