[Solved] Particle System forward doesn't work and animated texture problem

Problems building or running the engine, queries about how to use features etc.
Post Reply
Ray1184
Gnoblar
Posts: 15
Joined: Thu Jan 07, 2021 3:47 pm
x 5

[Solved] Particle System forward doesn't work and animated texture problem

Post by Ray1184 »

Ogre Version: 13.4.4
Operating System: Windows 11
Render System: OpenGL

Hi everyone
I'm using particle systems for rendering a firearm bullet explosion, but I've got 2 problems:

PROBLEM 1
When the bullet explode the explosion particle system starts more or less 1 second after the hit. Checking the explosion tutorial I tried with this:

Code: Select all

void hpms::ParticleAdaptee::GoToTime(float time)
{
    Check();
    ogrePS->fastForward(time);
}

Where ogrePS is an instance of Ogre::ParticleSystem, but also calling GoToTime(1.0) it seems not working.
This is the .particle file, and setting the emitter emission_rate higher (10 for example) the problem doesn't occurs (but I'd like to understand why the fastForward doesn't work)

Code: Select all

particle_system GunFX/ShotExplosion1
{
	material FX/Explosion
	particle_width 1
	particle_height 1
	cull_each true
	quota 1
	billboard_type point
	sorted true

	emitter Point
	{
		angle 180
		duration 1
		emission_rate 1
		time_to_live 1
		direction 0 0 0
		velocity 0
	}

	affector ColourFader
	{
		alpha -1
	}
}

PROBLEM 2
The particle system uses an animated texture, with this material:

Code: Select all

material FX/Explosion
{
	technique
	{
		pass
		{
			lighting off
			scene_blend add

		texture_unit
		{
			anim_texture Materials/E.png 16 1
		}
	}
}
}

On first hit it's ok, the explosion starts at image E_0.png and ends on E_15.png. But if I try to shot again, seems starting on the middle and finishing on the middle of animation. This is very strange, because I create a new particle system foreach bullet when there's a collision, and I destroy it after 2 seconds, so I cannot understand why the animation doesn't start every time at frame 0.

Thanks for help in advance

Ray

Last edited by Ray1184 on Thu Oct 06, 2022 9:36 pm, edited 1 time in total.
rpgplayerrobin
Gnoll
Posts: 619
Joined: Wed Mar 18, 2009 3:03 am
x 353

Re: Particle System forward doesn't work and animated texture problem

Post by rpgplayerrobin »

Where ogrePS is an instance of Ogre::ParticleSystem, but also calling GoToTime(1.0) it seems not working.

I have also had problems with that function. It seems to be bugged/flawed.
This is the code I use for my CParticle class instead:

Code: Select all

// Fast forwards the particle
void CParticle::FastForward(float seconds)
{
	// Fast forward the particle system
	const float tmpDT = 1.0f / 60.0f;
	m_particleSystem->setSpeedFactor(1.0f); // Only do this line if you manually update your particle systems
	for(; seconds > 0.0f; seconds -= tmpDT)
		m_particleSystem->_update(tmpDT);
	m_particleSystem->setSpeedFactor(0.0f); // Only do this line if you manually update your particle systems
}

On first hit it's ok, the explosion starts at image E_0.png and ends on E_15.png. But if I try to shot again, seems starting on the middle and finishing on the middle of animation. This is very strange, because I create a new particle system foreach bullet when there's a collision, and I destroy it after 2 seconds, so I cannot understand why the animation doesn't start every time at frame 0.

This is actually very logical.
First of all, if you used that material on multiple particles at once (in one particle emitter or even different particle emitters) you would get exactly the same animated texture for all of the particles.
The material does not know what particle it is on, which makes it impossible to reset it correctly, since it would be completely arbitrary.
Even if you somehow reset the material by code when a new particle is created, it would bug all other particles currently shown with that material.
What you actually want is an atlas texture, which I think your version of Ogre supports for particle (I implemented my own particle atlas texture system in my game).
That way each particle is unique and will always start from the beginning like you would want to.
I can not find much about this system in Ogre, but maybe this?: https://ogrecave.github.io/ogre/api/13/ ... otoc_md221

Ray1184
Gnoblar
Posts: 15
Joined: Thu Jan 07, 2021 3:47 pm
x 5

Re: Particle System forward doesn't work and animated texture problem

Post by Ray1184 »

Thank you very much!!!
The workaround you suggest for the first problem works!!
For the second problem I will check for the atlas texture, I suspected it was a material issue.
Thanks again!

Ray

Post Reply