How to do it...

The vertex shader attributes include per-particle values and mesh values:

// Mesh attributeslayout (location = 0) in vec3 VertexPosition;layout (location = 1) in vec3 VertexNormal;// Per-particle attributeslayout (location = 3) in vec3 ParticlePosition;layout (location = 4) in vec3 ParticleVelocity;layout (location = 5) in float ParticleAge;layout (location = 6) in vec2 ParticleRotation;

We include output variables for transform feedback, used during the update pass, and for the fragment shader, used during the render pass:

// To transform feedbackout vec3 Position;out vec3 Velocity;out float Age;out vec2 Rotation;// To fragment shaderout vec3 fPosition;out vec3 fNormal;

The update function (vertex shader) is similar ...

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.