Particle system fade out affector not working

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Donald Duck
Posts: 34
Joined: Sat Jan 21, 2017 6:51 pm
Location: Duckburg
Contact:

Particle system fade out affector not working

Post 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?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Particle system fade out affector not working

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Donald Duck
Posts: 34
Joined: Sat Jan 21, 2017 6:51 pm
Location: Duckburg
Contact:

Re: Particle system fade out affector not working

Post 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?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Particle system fade out affector not working

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: Particle system fade out affector not working

Post 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);
 
kornwaretm
Competition winner
Posts: 189
Joined: Tue Oct 16, 2007 3:53 am
Location: Indonesia
Contact:

Re: Particle system fade out affector not working

Post 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.
Post Reply