From d4b9ccf499fb8ce8b5098a465a90eb1ad2c64f45 Mon Sep 17 00:00:00 2001 From: vincentlj Date: Mon, 30 Dec 2013 13:57:55 +0000 Subject: [PATCH] GPUParticles: Particles don't follow their source. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14838 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/shaders/pointemitter.vert | 5 +++-- src/graphics/gpuparticles.cpp | 7 +++---- src/graphics/gpuparticles.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/data/shaders/pointemitter.vert b/data/shaders/pointemitter.vert index b3a236c26..ef3581224 100644 --- a/data/shaders/pointemitter.vert +++ b/data/shaders/pointemitter.vert @@ -1,6 +1,6 @@ #version 130 uniform int dt; -uniform vec3 source; +uniform mat4 sourcematrix; uniform int duration; in vec3 particle_position; @@ -13,7 +13,8 @@ out vec4 new_particle_velocity; void main(void) { - new_particle_position = (lifetime > 0.) ? particle_position + particle_velocity.xyz * float(dt) : vec3(0., 0., 0.); + vec4 initialposition = sourcematrix * vec4(0., 0., 0., 1.0); + new_particle_position = (lifetime > 0.) ? particle_position + particle_velocity.xyz * float(dt) : initialposition.xyz; new_lifetime = (lifetime > 0.) ? lifetime - float(dt) : float(duration); new_particle_velocity = particle_velocity; gl_Position = vec4(0.); diff --git a/src/graphics/gpuparticles.cpp b/src/graphics/gpuparticles.cpp index b698ee884..3eb540b26 100644 --- a/src/graphics/gpuparticles.cpp +++ b/src/graphics/gpuparticles.cpp @@ -234,7 +234,7 @@ PointEmitter::PointEmitter(scene::ISceneNode *parent, SimulationProgram = LoadTFBProgram(file_manager->getAsset("shaders/pointemitter.vert").c_str(), varyings, 3); loc_duration = glGetUniformLocation(SimulationProgram, "duration"); loc_dt = glGetUniformLocation(SimulationProgram, "dt"); - loc_source = glGetUniformLocation(SimulationProgram, "source"); + loc_sourcematrix = glGetUniformLocation(SimulationProgram, "sourcematrix"); loc_position = glGetAttribLocation(SimulationProgram, "particle_position"); loc_lifetime = glGetAttribLocation(SimulationProgram, "lifetime"); loc_velocity = glGetAttribLocation(SimulationProgram, "particle_velocity"); @@ -272,6 +272,7 @@ PointEmitter::PointEmitter(scene::ISceneNode *parent, void PointEmitter::simulate() { + core::matrix4 matrix = m_node->getAbsoluteTransformation(); glUseProgram(SimulationProgram); glEnable(GL_RASTERIZER_DISCARD); glEnableVertexAttribArray(0); @@ -285,7 +286,7 @@ void PointEmitter::simulate() glUniform1i(loc_dt, 1); glUniform1i(loc_duration, duration); - glUniform3f(loc_source, getPosition().X, getPosition().Y, getPosition().Z); + glUniformMatrix4fv(loc_sourcematrix, 1, GL_FALSE, matrix.pointer()); glBeginTransformFeedback(GL_POINTS); glDrawArrays(GL_POINTS, 0, count); glEndTransformFeedback(); @@ -298,13 +299,11 @@ void PointEmitter::simulate() void PointEmitter::draw() { - updateAbsolutePosition(); glDisable(GL_ALPHA_TEST); glDepthMask(GL_FALSE); glEnable(GL_BLEND); core::matrix4 matrix = irr_driver->getVideoDriver()->getTransform(video::ETS_PROJECTION); matrix *= irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW); - matrix *= m_node->getAbsoluteTransformation(); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); glEnable(GL_POINT_SPRITE); glBlendEquation(GL_FUNC_ADD); diff --git a/src/graphics/gpuparticles.h b/src/graphics/gpuparticles.h index 1b3bfa958..379745752 100644 --- a/src/graphics/gpuparticles.h +++ b/src/graphics/gpuparticles.h @@ -29,7 +29,7 @@ class PointEmitter : public GPUParticle { protected: GLuint SimulationProgram, RenderProgram; - GLuint loc_duration, loc_source, loc_dt, loc_matrix, loc_texture, loc_normal_and_depths, loc_screen, loc_invproj; + GLuint loc_duration, loc_sourcematrix, loc_dt, loc_matrix, loc_texture, loc_normal_and_depths, loc_screen, loc_invproj; GLuint loc_position, loc_velocity, loc_lifetime; GLuint tfb_buffers[2]; GLuint texture, normal_and_depth;