physics = GL.NewComputeShader(''' #version 430 struct Circle { vec2 pos; float radius; }; struct Particle { vec2 prev; vec2 pos; vec2 acc; }; uniform Circles { int circles; Circle circle[64]; }; layout (binding = 0) buffer Input { Particle particle[]; }; layout (local_size_x = 256, local_size_y = 1, local_size_z = 1) in; void update(inout Particle p) { vec2 pos = p.pos * 2 - p.prev + p.acc; p.prev = p.pos; p.pos = pos; for (int i = 0; i < circles; ++i) { vec2 sub = p.pos - circle[i].pos; float r = circle[i].radius + 2.5; if (dot(sub, sub) < r * r) { vec2 dir = p.pos - p.prev; p.pos = circle[i].pos + normalize(sub) * r; p.prev = p.pos - reflect(dir, normalize(sub)) * 0.7; } } } void main() { update(particle[gl_GlobalInvocationID.x]); } ''')
# GL.DisableAttributes() # GL.EnableAttributes() # GL.LineSize() # GL.PointSize() cs = GL.NewComputeShader(''' #version 430 layout (binding = 0) buffer Input { int A[4][4][4]; }; layout (binding = 1) buffer Output { int B[4][4][4]; }; layout (local_size_x = 2, local_size_y = 2, local_size_z = 2) in; void main() { B[gl_GlobalInvocationID.x][gl_GlobalInvocationID.y][gl_GlobalInvocationID.z] = A[gl_GlobalInvocationID.x][gl_GlobalInvocationID.y][gl_GlobalInvocationID.z]; } ''') A = GL.NewStorageBuffer(struct.pack('64i', *[1 + i for i in range(64)])) B = GL.NewStorageBuffer(b'\x00' * 256) C = GL.NewStorageBuffer(b'\x00' * 256) BX = GL.NewStorageBuffer(b'\x00' * 256) BY = GL.NewStorageBuffer(b'\x00' * 256)