How it works...

The vertex shader receives the particle's initial velocity (VertexInitVel) and start time (VertexBirthTime) in its two input attributes. The Time variable stores the amount of time that has elapsed since the beginning of the animation. The Transp output variable is the overall transparency of the particle.

In the main function of the vertex shader, we start by determining the particle's age (t) as the current simulation time minus the particle's birth time. The following if statement determines whether the particle is alive yet. If the particle's age is greater than zero, the particle is alive, otherwise, the particle has yet to be born. In the latter case, the position is set to the camera's origin and the particle is rendered ...

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.