#version 450 layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; // layout(set = 0, binding = 0, rgba32f) uniform imageBuffer posvelbuff; layout(std430, set = 0, binding = 0) buffer _ { vec4 posvel[]; } posvelbuff; void main() { float delta_time = 0.00001; int index = int(gl_GlobalInvocationID.x) + 1024 * int(gl_GlobalInvocationID.y); vec4 posvel = posvelbuff.posvel[index]; vec2 pos = posvel.rg; vec2 vel = posvel.ba; pos += vel + (delta_time * delta_time) / 2; vel.y -= delta_time; if (pos.y < 0.0) { pos.y = -pos.y; vel.y *= -1.0; } if (pos.y > 1.0) { pos.y = 2.0 - pos.y; vel.y *= -1.0; } if (pos.x < 0.0) { pos.x = -pos.x; vel.x *= -1.0; } if (pos.x > 1.0) { pos.x = 2.0 - pos.x; vel.x *= -1.0; } vel = clamp(vel, vec2(-0.02, -0.02), vec2(0.02, 0.02)); posvelbuff.posvel[index] = vec4(pos, vel); }