Translucent ITexture (load from png) Fade out animation

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
jack_fantasy
Posts: 6
Joined: Fri Feb 19, 2016 10:55 pm

Translucent ITexture (load from png) Fade out animation

Post by jack_fantasy »

Hi, everyone

I have a set of image mesh scene nodes, their textures are loaded from translucent pngs (some parts may have 0.0 alpha other parts may have 1.0 alpha). I set their MaterialType to video::EMT_TRANSPARENT_ALPHA_CHANNEL. Image mesh scene nodes are rendered as expected.

My question is how to create the fade out animation on my image scene nodes in irrlicht without manipulating alpha in the pixel shader?

My original thought we could use blend operation similar to using GL_CONSTANT_ALPHA and glBlendFunc in OpenGL. But I couldn't find a GL_CONSTANT_ALPHA equivalent in irrlicht.

Thank you,
jack_fantasy
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Translucent ITexture (load from png) Fade out animation

Post by hendu »

For what you need, writing a shader is the simplest solution.
jack_fantasy
Posts: 6
Joined: Fri Feb 19, 2016 10:55 pm

Re: Translucent ITexture (load from png) Fade out animation

Post by jack_fantasy »

Thank you, hendu
hendu wrote:For what you need, writing a shader is the simplest solution.
Right, I thought that could be done by a shader. I have a hierarchy of custom scene node classes (some of them already requiring a shader), if I need a unified way to create a fade out animation for my scene nodes. I have to create a shader for every classes and I also need to override some shaders in my class hierarchy. Suddenly a fade out animation problem becomes an architecture design problem which I am trying to avoid. Do we have any other alternatives to solve this problem in irrlicht?

Jack_fantasy
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Translucent ITexture (load from png) Fade out animation

Post by CuteAlien »

Would have to experiment myself. But maybe you could set EMT_TRANSPARENT_VERTEX_ALPHA and then change the alpha values of the mesh-vertices. Thought you'd have to ensure each node has it's own mesh (so they don't affect each other) and not sure if it's still useable if you need to mix it with other alpha values (like texture alpha).
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
jack_fantasy
Posts: 6
Joined: Fri Feb 19, 2016 10:55 pm

Re: Translucent ITexture (load from png) Fade out animation

Post by jack_fantasy »

Thanks, CuteAlien

I have tried EMT_TRANSPARENT_VERTEX_ALPHA with a custom vertex colour. I think EMT_TRANSPARENT_VERTEX_ALPHA only takes the vertex alpha into account, not the texture alpha.

I have tried combinations of EMT_TRANSPARENT_VERTEX_ALPHA, EMT_TRANSPARENT_ALPHA_CHANNEL and EMT_ONETEXTURE_BLEND with following code:

Code: Select all

Material.MaterialType = video::EMT_ONETEXTURE_BLEND;
Material.MaterialTypeParam = video::pack_texureBlendFunc( 
                video::EBF_SRC_ALPHA, 
                video::EBF_ONE_MINUS_SRC_ALPHA,
                video::EMFN_MODULATE_1X, 
                video::EAS_TEXTURE | video::EAS_VERTEX_COLOR);
 
smgr->MeshManipulator->setVertexColor(mesh, SColor(127,0,0,0)); 
It doesn't work, only take one alpha value into account.

I am looking for a simple mechanism (a root alpha value) to control the scene node transparency regardless how many alpha values in various parts of the scene node.

jack_fantasy
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Translucent ITexture (load from png) Fade out animation

Post by hendu »

There isn't one. The built-in materials all only take one alpha, for more than that you have to use shaders.

If some of your nodes already use shaders, you cannot override their alpha output with material flags anyhow.


If you need to fade them all out in unison, maybe you could use a RTT? Render them into it, then fade that RTT out in a single shader.
jack_fantasy
Posts: 6
Joined: Fri Feb 19, 2016 10:55 pm

Re: Translucent ITexture (load from png) Fade out animation

Post by jack_fantasy »

Thanks, hendu

It looks like this is not simple problem as I thought. There are a few threads about this topic. People have already asked something like what I thought. Probably, I have to go with manipulating alphas in shaders at this stage.

jack_fantasy
Post Reply