GPUParticles: Fix orientation of reemitted particles.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14875 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
vincentlj 2014-01-01 19:13:57 +00:00
parent 6b7e33a267
commit be93478687
3 changed files with 10 additions and 2 deletions

View File

@ -1,6 +1,7 @@
#version 130
uniform int dt;
uniform mat4 sourcematrix;
uniform mat4 tinvsourcematrix;
in vec3 particle_position_initial;
in float lifetime_initial;
@ -20,9 +21,11 @@ out float new_size;
void main(void)
{
vec4 initialposition = sourcematrix * vec4(particle_position_initial, 1.0);
vec4 adjusted_initial_velocity = tinvsourcematrix * vec4(particle_velocity_initial, 1.0);
adjusted_initial_velocity /= adjusted_initial_velocity.w;
new_particle_position = (lifetime < 1.) ? particle_position + particle_velocity.xyz * float(dt) : initialposition.xyz;
new_lifetime = (lifetime < 1.) ? lifetime + (float(dt)/lifetime_initial) : 0.;
new_particle_velocity = (lifetime < 1.) ? particle_velocity : particle_velocity_initial;
new_particle_velocity = (lifetime < 1.) ? particle_velocity : adjusted_initial_velocity.xyz;
new_size = size_initial;
gl_Position = vec4(0.);
}

View File

@ -381,6 +381,7 @@ void ParticleSystemProxy::setEmitter(scene::IParticleEmitter* emitter)
uniform_dt = glGetUniformLocation(SimulationProgram, "dt");
uniform_sourcematrix = glGetUniformLocation(SimulationProgram, "sourcematrix");
uniform_tinvsourcematrix = glGetUniformLocation(SimulationProgram, "tinvsourcematrix");
attrib_position = glGetAttribLocation(SimulationProgram, "particle_position");
attrib_lifetime = glGetAttribLocation(SimulationProgram, "lifetime");
@ -434,6 +435,9 @@ void ParticleSystemProxy::simulate()
LastEmitTime = time;
core::matrix4 matrix = getAbsoluteTransformation();
core::matrix4 tinvmatrix;
matrix.getInverse(tinvmatrix);
tinvmatrix = tinvmatrix.getTransposed();
glUseProgram(SimulationProgram);
glEnable(GL_RASTERIZER_DISCARD);
glEnableVertexAttribArray(attrib_position);
@ -458,6 +462,7 @@ void ParticleSystemProxy::simulate()
glUniform1i(uniform_dt, 16);
glUniformMatrix4fv(uniform_sourcematrix, 1, GL_FALSE, matrix.pointer());
glUniformMatrix4fv(uniform_tinvsourcematrix, 1, GL_FALSE, tinvmatrix.pointer());
glBeginTransformFeedback(GL_POINTS);
glDrawArrays(GL_POINTS, 0, count);
glEndTransformFeedback();

View File

@ -34,7 +34,7 @@ protected:
GLuint SimulationProgram;
GLuint attrib_position, attrib_velocity, attrib_lifetime, attrib_initial_position, attrib_initial_velocity, attrib_initial_lifetime, attrib_size, attrib_initial_size;
GLuint uniform_duration, uniform_sourcematrix, uniform_dt;
GLuint uniform_duration, uniform_sourcematrix, uniform_tinvsourcematrix, uniform_dt;
GLuint RenderProgram;
GLuint attrib_pos, attrib_lf, attrib_quadcorner, attrib_texcoord, attrib_sz;