How to do it...

In the vertex shader code, we create the particle by offsetting the particle position in camera coordinates. Note the use of gl_VertexID to identify the quad's vertex:

layout (location = 0) in vec3 VertexInitVel;    // Particle initial velocitylayout (location = 1) in float VertexBirthTime; // Particle birth timeout float Transp;  // Transparency of the particleout vec2 TexCoord; // Texture coordinateuniform float Time; // Animation timeuniform vec3 Gravity; // Gravity vector in world coordsuniform float ParticleLifetime; // Max particle lifetimeuniform float ParticleSize; // Particle sizeuniform vec3 EmitterPos;    // Emitter position in world coordinates// Transformation matricesuniform mat4 MV, Proj;// Offsets to the position ...

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.