Uses floating point texture. Calculates lorenz stuff
This commit is contained in:
parent
52963a17df
commit
4c53f46674
3 changed files with 34 additions and 11 deletions
|
@ -7,5 +7,6 @@ in vec2 tex_coord_int;
|
|||
out vec4 fragColor;
|
||||
|
||||
void main(){
|
||||
fragColor = texture(tex, tex_coord_int);
|
||||
// fragColor = texture(tex, tex_coord_int);
|
||||
fragColor = vec4(0.5) + 0.5*sin(0.1 * texture(tex, tex_coord_int));
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ kernel void initialize(size_t width, size_t height, write_only image2d_t output)
|
|||
size_t y = get_global_id(1);
|
||||
|
||||
int2 coord = {x, y};
|
||||
//uint4 color = {255 * x / (width - 1), 255 * y / (height - 1), 0, 255};
|
||||
//uint4 color = {255 * (x%2), 120 * (y%2), 0, 255};
|
||||
uint4 color = {255, 255, 0, 255};
|
||||
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_imageui(output, coord, color);
|
||||
write_imagef(output, coord, color);
|
||||
}
|
||||
|
||||
kernel void update(size_t width, size_t height, read_only image2d_t input, write_only image2d_t output){
|
||||
|
@ -20,8 +20,19 @@ kernel void update(size_t width, size_t height, read_only image2d_t input, write
|
|||
const sampler_t samplerA = CLK_NORMALIZED_COORDS_FALSE
|
||||
| CLK_ADDRESS_NONE
|
||||
| CLK_FILTER_NEAREST;
|
||||
uint4 color = read_imageui(input, samplerA, coord).yzxw;
|
||||
color.x = 255 - color.x;
|
||||
write_imageui(output, coord, color);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
17
src/main.cpp
17
src/main.cpp
|
@ -58,6 +58,8 @@ struct App {
|
|||
size_t W = 128;
|
||||
size_t H = 128;
|
||||
|
||||
float wait = 2;
|
||||
|
||||
enum {
|
||||
POS_ATTR,
|
||||
TEX_ATTR
|
||||
|
@ -93,7 +95,7 @@ struct App {
|
|||
moggle::gl::active_texture(GL_TEXTURE0);
|
||||
moggle::gl::generate_textures(1, &tex);
|
||||
moggle::gl::bind_texture(GL_TEXTURE_2D, tex);
|
||||
moggle::gl::texture_image_2d(GL_TEXTURE_2D, 0, GL_RGBA, W, H, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
moggle::gl::texture_image_2d(GL_TEXTURE_2D, 0, GL_RGBA32F, W, H, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
moggle::gl::texture_parameter_i(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
moggle::gl::texture_parameter_i(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
return tex;
|
||||
|
@ -157,9 +159,16 @@ struct App {
|
|||
}
|
||||
|
||||
void draw(){
|
||||
time += 1/60.0f;
|
||||
auto dt = 1/60.0;
|
||||
time += dt;
|
||||
if(wait > 0) wait -= dt;
|
||||
|
||||
if(wait <= 0){
|
||||
for(int i = 0; i < 1; ++i){
|
||||
cl::checky((*k_update)(*cl_queue, W, H, W, H, *cl_image, *cl_image));
|
||||
}
|
||||
}
|
||||
|
||||
cl::checky((*k_update)(*cl_queue, W, H, W, H, *cl_image, *cl_image));
|
||||
cl::checky(cl_queue->finish());
|
||||
|
||||
moggle::gl::clear_color(0.65f, 0.65f, 0.65f, 1.0f);
|
||||
|
@ -176,6 +185,8 @@ struct App {
|
|||
}
|
||||
|
||||
void resize(size_t w, size_t h){
|
||||
wait = 2;
|
||||
|
||||
W = w;
|
||||
H = h;
|
||||
|
||||
|
|
Reference in a new issue