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 = mix(-2.0, 2.0, texelFetch(RandomTex, 2 *
gl_VertexID + 1, 0).r);
return Emitter + vec3(offset, 0, 0);
}

In the fragment shader, we mix the color with black proportional to the age of the particle. This gives the effect of the flame turning to smoke as it rises:

FragColor = texture(ParticleTex, TexCoord);
// Mix with black as it gets older, to simulate a bit of smoke
FragColor = vec4(mix( vec3(0,0,0), FragColor.xyz, Transp ), FragColor.a);
FragColor.a *= Transp;
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.183.150