Page 1 of 1

Particle system fade out affector not working

Posted: Wed Mar 08, 2017 7:36 pm
by Donald Duck
I'm trying to make a particle system in Irrlicht with a fade out affector. Here is my code:

Code: Select all

irr::scene::IParticleSystemSceneNode *particleSystem = sceneManager->addParticleSystemSceneNode(true, 0, -1, irr::core::vector3df(0, 0, 0), irr::core::vector3df(0, 0, 0), irr::core::vector3df(1, 1, 1));
irr::scene::IParticleEmitter *emitter = particleSystem->createBoxEmitter(irr::core::aabbox3d<irr::f32>(-0.03f, 0, -0.03f, 0.03f, 0.01f, 0.03f), irr::core::vector3df(0, 0.0001f, 0), 3, 7, irr::video::SColor(0, 0, 0, 0), irr::video::SColor(0, 20, 20, 20), 5000, 6000, 10, irr::core::dimension2df(0.06f, 0.06f), irr::core::dimension2df(0.12f, 0.12f));
particleSystem->setEmitter(emitter);
emitter->drop();
particleSystem->setMaterialTexture(0, driver->getTexture("image.png"));
particleSystem->setMaterialType(irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL);
particleSystem->setMaterialFlag(irr::video::EMF_LIGHTING, false);
irr::scene::IParticleAffector *affector = particleSystem->createFadeOutParticleAffector(irr::video::SColor(0, 0, 0, 0), 7000);
particleSystem->addAffector(affector);
affector->drop();
Here is image.png:

Image

The problem is that the fade out affector doesn't do anything. I get exactly the same result if I comment the last three lines.

How can I get it to work?

Re: Particle system fade out affector not working

Posted: Thu Mar 09, 2017 11:11 am
by CuteAlien
That one does set the vertex-color, so it has to be a material which does use the vertex-color. Documentation says it will work well with EMT_TRANSPARENT_ADD_COLOR. I guess EMT_TRANSPARENT_ALPHA_CHANNEL probably ignores vertex-colors so if you would like that specific kind of color-combination you will need to use a shader.

Re: Particle system fade out affector not working

Posted: Thu Mar 09, 2017 12:39 pm
by Donald Duck
I tried EMT_TRANSPARENT_ADD_COLOR and then the particle system was completely invisible. That's probably because as far as I understand, EMT_TRANSPARENT_ADD_COLOR changes everything that's black to transparent and since the texture is either black or transparent everywhere, it becomes completely transparent. That's why I used EMT_TRANSPARENT_ALPHA_CHANNEL. What's the solution to this?

Re: Particle system fade out affector not working

Posted: Thu Mar 09, 2017 10:37 pm
by CuteAlien
Sorry, I don't think there is a default material which mixes the alpha of vertices and textures. I suppose this needs a custom shader.

Re: Particle system fade out affector not working

Posted: Fri Mar 10, 2017 2:41 pm
by MartinVee
Have you tried..?

Code: Select all

 
  setMaterialType(video::EMT_ONETEXTURE_BLEND);
  setMaterialFlag(EMF_COLOR_MATERIAL, true);
 
  getMaterial(0).MaterialTypeParam = irr::video::pack_textureBlendFunc(irr::video::EBF_SRC_ALPHA, irr::video::EBF_ONE_MINUS_SRC_ALPHA, irr::video::EMFN_MODULATE_1X, irr::video::EAS_TEXTURE | irr::video::EAS_VERTEX_COLOR);
  getMaterial(0).setFlag(EMF_BLEND_OPERATION, true);
 

Re: Particle system fade out affector not working

Posted: Sun Mar 12, 2017 11:36 pm
by kornwaretm
Donald Duck wrote:I tried EMT_TRANSPARENT_ADD_COLOR and then the particle system was completely invisible. That's probably because as far as I understand, EMT_TRANSPARENT_ADD_COLOR changes everything that's black to transparent and since the texture is either black or transparent everywhere, it becomes completely transparent. That's why I used EMT_TRANSPARENT_ALPHA_CHANNEL. What's the solution to this?
if you want an easy solution, use EMT_TRANSPARENT_ADD_COLOR and don't use black as the primary object color(in irrlicht media folder there is one or two texture sample). if you still need it black, than you need shader as CuteAlien mentioned. use EMT_TRANSPARENT_ALPHA_CHANNEL, and in shader just multiply texture alpha with vertex alpha, this way, you will get both the texture alpha and the fading alpha.