Vertex Shader Particle Movement

I want to move my particles by a few given attributes. The particles should slow down to a stop as they reach the end of their lifetime

result = a_pos + a_direction * lifetime * mix(a_speed, a_speed_end, normalized_lifetime);
result.w = 1.0;
gl_Position = u_projection * u_model_view * result;

This doesn't work as I'd hoped it would because it doesn't consider previous movements, so when normalized_lifetime reaches 1, the particle is basically set to a_pos again since a_speed_end is 0. How do I go about this?

EDIT: More information:

a_pos = startposition

a_direction = normalized direction vector

lifetime = current lifetime of the particle

a_speed, a_speed_end = desired start/end speed

They should move on a straight line along the direction vector, no CPU updates


you want a equation like -a_deceleration*t^2+a_initial*t+a_pos

a bit of physics:

initial speed is a_speed a_speed_end is a_speed - a_deceleration*total_life so -a_deceleration = (a_speed_end-a_speed)/total_life

so your equation becomes

result = a_pos + a_direction * lifetime * a_speed 
               + a_direction * normalized_lifetime * normalized_lifetime * (a_speed_end-a_speed);

edit: looking at the formulas in wikipedia there is an easier one

result = a_pos + a_direction * lifetime * (a_speed + mix(a_speed, a_speed_end, normalized_lifetime))/2

Thanks for ratchet freak for pointing me to the right direction, helped a lot! The final solution was to calculate the acceleration first

a_acceleration = (endspeed - startspeed) / total_lifetime;

The final formula is then:

pos = a_pos + ((0.5 * a_acceleration * current_lifetime * current_lifetime) + (a_start_speed * current_lifetime)) * a_direction;
pos.w = 1.0;
gl_Position = u_projection * u_model_view * pos;

For example, with a startspeed of 5, endspeed of 0 and lifetime of 5 the particle will slowly decelerate and come to a total stop after 5 seconds.

Need Your Help

j_spring_security_check 404

java spring spring-security

We are trying to upgrade an existing web application from Spring 2.x to Spring 3 and believe we are on the last issue before everything is working again. We use CAS, and can get to the JASIG CAS lo...

apache - website - windows authentication

windows apache authentication web

I would like to use my Windows credentials to log on to my website. I don't want something like LDAP. Let's say I log in to my Windows account and then I enter the URL of my website. When I hit ent...