Blend Question( alpha )

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.
xsocom
Posts: 80
Joined: Thu Sep 13, 2007 8:34 am

Blend Question( alpha )

Post by xsocom »

In opengl I can do like this to change alpha on models:

glEnable(GL_TEXTURE_2D);
glEnable( GL_ALPHA_TEST );
glEnable( GL_BLEND );

glColor4f( 1.0f, 1.0f, 1.0f, pAlpha );

RenderModel.

glDisable( GL_BLEND );

what is the best way in irrlicht engine? Already exist some function to do this to apply on a animated node?
xsocom
Posts: 80
Joined: Thu Sep 13, 2007 8:34 am

Post by xsocom »

No function to set the alpha value of nodes?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You're trying vertex alpha as it seems, so use EMT_TRANSPARENT_VERTEX_ALPHA.
xsocom
Posts: 80
Joined: Thu Sep 13, 2007 8:34 am

Post by xsocom »

Yes I have tryed to set the materialType to EMT_TRANSPARENT_VERTEX_ALPHA and reduse the alpha, but it seems it does not work as it should, I can post some screen when I get home. I use 1.4.2 version.

Anyway, I have been trying to use alpha channels on the GUI Image and it works perfekt, Does it not exist that sort of alpha channel option on normal node textures on models?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Of course, you'd use EMT_TRANSPARENT_ALPHA_CHANNEL. All covered in the API manuals...
The question is how you changed the alpha value. If you use VERTEX_ALPHA you have to change the vertex colors. You cannot use plain glColor4f because that's overridden by the draw commands in Irrlicht.
xsocom
Posts: 80
Joined: Thu Sep 13, 2007 8:34 am

Post by xsocom »

so can I do like this?

Material Options.

node->setMaterialFlag( EMF_LIGHTING, false );
node->setMaterialType( video::EMT_TRANSPARENT_VERTEX_ALPHA );


Disable BackfaceCulling.
node->getMaterial(0).BackfaceCulling = false;

Scene Options.
pSmgr->getParameters()->setAttribute( scene::ALLOW_ZWRITE_ON_TRANSPARENT, true );
pSmgr->getMeshManipulator()->setVertexColorAlpha( node->getMesh(), 50.0f );
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, that's exactly the code that you'll need, besides the vertex alpha value (should be 50, not 50.0f, because it's an int in the range [0,255]).
xsocom
Posts: 80
Joined: Thu Sep 13, 2007 8:34 am

Post by xsocom »

Ok I try it out thanks
xsocom
Posts: 80
Joined: Thu Sep 13, 2007 8:34 am

Post by xsocom »

Ok Result.


This is with no parameters at all and I want to make the black transparent, Textures is .png and it works just fine to make them transparent in the GUI Editor and option enable alpha channel.


This is the result using the parameters:

node->setMaterialFlag( EMF_LIGHTING, false );
node->setMaterialType( video::EMT_TRANSPARENT_VERTEX_ALPHA );
node->getMaterial(0).BackfaceCulling = false;

pSmgr->getParameters()->setAttribute( scene::ALLOW_ZWRITE_ON_TRANSPARENT, true );
pSmgr->getMeshManipulator()->setVertexColorAlpha( node->getMesh(), 50 );


Maybe use some shaders then? Im not good at using them but something like this maybe?

float4 gl_FragColor;
gl_FragColor.rgb = tex2D(Texture, i.TexCoord0.xy);
gl_FragColor.a = fadeParameter;

Duno maybe someone else can explain.
Last edited by xsocom on Fri Dec 05, 2008 5:11 pm, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

So do you want to change the overall alpha, or do you want to use the alpha channel?
xsocom
Posts: 80
Joined: Thu Sep 13, 2007 8:34 am

Post by xsocom »

I just want the black on the textures to be gone.. not the whole model as on the 2nd picture.
zeroZshadow
Posts: 43
Joined: Mon Dec 01, 2008 6:35 pm

Post by zeroZshadow »

what texture format are you using ??
if you use TGA, you can add alpha on the parts you want to be invisible and just save it 32 bit.

the use EMT_TRANSPARANT_ALPHA_CHANNEL_REF or EMT_TRANSPARANT_ALPHA_CHANNEL as material to make it work ingame
xsocom
Posts: 80
Joined: Thu Sep 13, 2007 8:34 am

Post by xsocom »

I use 32bit TGA, What did you mean by set the material to EMT_TRANSPARANT_ALPHA_CHANNEL?

entity->node->setMaterialType( EMT_TRANSPARANT_ALPHA_CHANNEL );

or?
zeroZshadow
Posts: 43
Joined: Mon Dec 01, 2008 6:35 pm

Post by zeroZshadow »

yup, that one.
the EMT_TRANSPARANT_ALPHA_CHANNEL will BLEND you texture depending on the alpha

and the EMT_TRANSPARANT_ALPHA_CHANNEL_REF will just draw the pixel or not, depending if the alpha is 127 or lower.
xsocom
Posts: 80
Joined: Thu Sep 13, 2007 8:34 am

Post by xsocom »

Ok seems to almost work :)

the result with:

Code: Select all

pSmgr->getParameters()->setAttribute( scene::ALLOW_ZWRITE_ON_TRANSPARENT, true );
node->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);

for( int i=0; i < (int)node->getMaterialCount(); i++ )
{
	node->getMaterial(i).BackfaceCulling = false;
	node->getMaterial(i).MaterialTypeParam = 0.01f;
}

Where is the body :D?

If I dont set the MaterialTypeParam to 0.01f then the body does not show up at all, How can I get full alpha on this part?


It made the first texture almost invisible, the body texture is the first one on the model.
Last edited by xsocom on Fri Dec 05, 2008 5:12 pm, edited 1 time in total.
Post Reply