How to do it...

Perform the following steps:

  1. We'll use the compute shader for updating the positions of the particles:
layout( local_size_x = 1000 ) in; uniform float Gravity1 = 1000.0; uniform vec3 BlackHolePos1; uniform float Gravity2 = 1000.0; uniform vec3 BlackHolePos2; uniform float ParticleInvMass = 1.0 / 0.1; uniform float DeltaT = 0.0005; layout(std430, binding=0) buffer Pos { vec4 Position[]; }; layout(std430, binding=1) buffer Vel { vec4 Velocity[]; }; void main() { uint idx = gl_GlobalInvocationID.x; vec3 p = Position[idx].xyz; vec3 v = Velocity[idx].xyz; // Force from black hole #1 vec3 d = BlackHolePos1 - p; vec3 force = (Gravity1 / length(d)) * normalize(d); // Force from black hole #2 d = BlackHolePos2 - p; force += (Gravity2 ...

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.