How it works...

We use 100 invocations per work group, 10 in each dimension. The first statement in the compute shader defines the number of invocations per work group:

layout( local_size_x = 10, local_size_y = 10 ) in; 

The uniform variables that follow define the constants in the force equations and the rest the lengths for each of the horizontal, vertical, and diagonal springs. The time step size is DeltaT. The position and velocity buffers are declared next. We define the position buffers at binding indexes 0 and 1, and the velocity buffers at indexes 2 and 3.

In the main function (step 4), we start by determining the number of particles in each dimension. This is going to be the same as the number of work groups times the work group ...

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.