How to do it...

We'll use a texture filled with random values (two values per particle). The first value will be used to generate the initial velocity and the second, the initial position. For the initial positions, instead of using the the emitter position for all particles, we offset that with random x location. When generating the initial velocities, we'll set the x and z components to zero and take the y component from the random texture.

This, combined with the chosen acceleration, makes each particle move in only the y (vertical) direction:

vec3 randomInitialVelocity() {    float velocity = mix(0.1, 0.5, texelFetch(RandomTex, 2 *     gl_VertexID, 0).r );    return EmitterBasis * vec3(0, velocity, 0);}vec3 randomInitialPosition() { float offset ...

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.