| 1 |
#version 440 |
| 2 |
|
| 3 |
layout (local_size_x = 256) in; |
| 4 |
|
| 5 |
struct Data |
| 6 |
{ |
| 7 |
vec2 pos; |
| 8 |
float dir; |
| 9 |
}; |
| 10 |
|
| 11 |
layout(std140, binding = 0) buffer StorageBuffer |
| 12 |
{ |
| 13 |
Data d[]; |
| 14 |
} buf; |
| 15 |
|
| 16 |
layout(std140, binding = 1) uniform UniformBuffer |
| 17 |
{ |
| 18 |
float step; |
| 19 |
uint count; |
| 20 |
} ubuf; |
| 21 |
|
| 22 |
void main() |
| 23 |
{ |
| 24 |
uint index = gl_GlobalInvocationID.x; |
| 25 |
if (index < ubuf.count) { |
| 26 |
vec2 p = buf.d[index].pos; |
| 27 |
float dir = buf.d[index].dir; |
| 28 |
|
| 29 |
p.x += dir * ubuf.step * 0.01; |
| 30 |
if (p.x > 1.0) { |
| 31 |
p.x = 1.0; |
| 32 |
buf.d[index].dir *= -1.0; |
| 33 |
} |
| 34 |
if (p.x < -1.0) { |
| 35 |
p.x = -1.0; |
| 36 |
buf.d[index].dir *= -1.0; |
| 37 |
} |
| 38 |
|
| 39 |
buf.d[index].pos = p; |
| 40 |
} |
| 41 |
} |