How to do it...

  1. Within the vertex shader, add the following uniforms:
uniform float MinParticleSize = 0.1; uniform float MaxParticleSize = 2.5; 
  1. Also, within the vertex shader, in the render function, we'll update the size of the particle based on its age:
void render() {    Transp = 0.0;    vec3 posCam = vec3(0.0);    if( VertexAge >= 0.0 ) {        float agePct = VertexAge / ParticleLifetime;        Transp = clamp(1.0 - agePct, 0, 1);        posCam =            (MV * vec4(VertexPosition,1)).xyz +            offsets[gl_VertexID] *            mix(MinParticleSize, MaxParticleSize, agePct);    }    TexCoord = texCoords[gl_VertexID];    gl_Position = Proj * vec4(posCam,1);} 

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.