How it works...

The compute shader starts by defining the number of invocations per work group using the layout specifier:

layout( local_size_x = 1000 ) in; 

This specifies 1000 invocations per work group in the x dimension. You can choose a value for this that makes the most sense for the hardware you're running. Just make sure to adjust the number of work groups appropriately. The default size for each dimension is one so we don't need to specify the size of the y and z directions.

Then, we have a set of uniform variables that define the simulation parameters. Gravity1 and Gravity2 are the strengths of the two black holes (G, in the preceding equation), and BlackHolePos1 and BlackHolePos2 are their positions. ParticleInvMass is the inverse ...

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.